Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Set a value during an insert

Author  Topic 

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-16 : 12:26:55
I'm trying to assign one value for a field during an insert. Can someone give me the appropriate syntax? thx :)

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-16 : 12:42:57
Let me re-clarify. I'm using an Insert statement with a select (dumping contents of one table to another), but I want to assign the value of one column in the process. thanks :).
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-16 : 12:43:33
Not sure about ur requirement, as there is not much in the question.
Please be more descriptive

Do you want to
Assign a value to a table using an insert statement?
Does ur table has more than one field and u want to add data to a particular field?
Do u want to have a particular data to be inserted along with a selected set of data?


Give an example along with ur table / column details and whatu want to do
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-16 : 12:45:47
May be this way

Insert into tableDestination (field1,field2,field3,field4)
Select field5, 'ABC', 324, field7 from tableSource
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-16 : 12:53:32
I tried that already. The value is 3 and when I try to insert ['3'], it tells me that it's an invalid column name. So far, my insert looks like this (trying your suggestion).

INSERT INTO [Development].[dbo].[USERS] [AccountNumber], [AdPrintId],[IsAdmin])
SELECT [AdvertiserURL], [AccountNumber],[AdPrintId],['3']
FROM [UScondex_Development].[dbo].[test_table]
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-16 : 12:58:34
Remove 2 square brackets sorrounding '3'
That assumes '3' to be a column name, which is not so
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-16 : 12:59:42
You're too cool...Thank you so much it worked :)
Go to Top of Page
   

- Advertisement -