Click here to Skip to main content
14,765,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I need help guys. I want to insert data in Table1 in my database selecting it from another table2 but table1 have another attribute for username (ComputerName).

What I have tried:

Example :

INSERT INTO [AffecAnalytique].[dbo].[C9_V]([C9],[V],[OID],[USERMODIF]) SELECT [C9],[V],[OID] FROM [AffecAnalytique].[dbo].[C9_V] WHERE [OID]='CEC4F038E3954AC79DBF7EC38B02171F' ,   'AHE'

AHE is the other attribute for username.
Updated 5-Oct-20 4:30am
F-ES Sitecore 5-Oct-20 9:27am
I don't understand the question, but if you want 'AHE' in the USERMODIF field then just do

INSERT INTO [AffecAnalytique].[dbo].[C9_V]([C9],[V],[OID],[USERMODIF]) SELECT [C9],[V],[OID], 'AHE' FROM [AffecAnalytique].[dbo].[C9_V] WHERE [OID]='CEC4F038E3954AC79DBF7EC38B02171F'
Maciej Los 5-Oct-20 9:30am
What's your problem?

1 solution

Your syntax is all over the place
INSERT INTO [AffecAnalytique].[dbo].[C9_V]
([C9],[V],[OID],[USERMODIF]) -- you have correctly listed the columns you want to insert
SELECT [C9],[V],[OID] -- but are not selecting the correct columns
FROM [AffecAnalytique].[dbo].[C9_V] WHERE [OID]='CEC4F038E3954AC79DBF7EC38B02171F'
 ,  'AHE'-- this is just meaningless random text at the end of your WHERE statement

INSERT INTO [AffecAnalytique].[dbo].[C9_V]([C9],[V],[OID],[USERMODIF]) SELECT [C9],[V],[OID],'AHE' FROM [AffecAnalytique].[dbo].[C9_V] WHERE [OID]='CEC4F038E3954AC79DBF7EC38B02171F'
although I doubt that is really what you want.

If you have defined the list of columns you want to add you just have to supply values for them. The column names do not need to be the same, but you do need to supply all the values

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900