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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 combining a value and a select statement into the insert statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-29 : 08:02:10
Robert writes "Ok, this may be simple to some, but it sure is a puzzle to me. I want to move a set of data from one table to another table with a similar structure. The problem is that the first column value needs to be a variable but the rest of the columns are just being duplicated with values already in there. Something like this but i know it doesn't work

insert into Request(field1,field2,field3)
values(variable value, duplicated values for field2 and field3 using a select statement.

here is an example that does not work

Insert Into Request (Membership_ID,Request_Type_code,
Comments_Txt,Request_date,
Request_Status_code,Request_status_date )
VALUES (5,(Select Membership_ID,Request_Type_code,Comments_Txt,
GetDate() AS RequestDate,'PROG' AS RequestStatusCode,
GetDate() AS RequestStatusDate from request))"

dsdeming

479 Posts

Posted - 2003-09-29 : 08:26:32
Try this:

Insert Into Request ( Membership_ID, Request_Type_code,
Comments_Txt, Request_date, Request_Status_code,
Request_status_date )
Select 5, Membership_ID, Request_Type_code, Comments_Txt,
GetDate() AS RequestDate,'PROG' AS RequestStatusCode,
GetDate() AS RequestStatusDate from request

Dennis
Go to Top of Page
   

- Advertisement -