Hi,
I need insert records into table1 if condition in table2 is met. The insert values include constant values and values that are selected from table2. How can I do it?
There are 10 fields in table1, 5 fields are constant value, 5 fields need to be selected from table2 when condition, such as table2.status ='N' met. So if table2.status ='N', then insert a record into table1 with 10 fields.
if all values are from table2, then I will do:
Insert into table1(f1,f2,f3,f4,f5...f10)
select f1,f2...f10
from table2
where table2.status ='N'
But I need to set values for f1 to f5 which are not select from table2, they are constant. How can I set the values at the same time when select others. I am working on SQL server 2008.
Thank you so much for any helps and suggestions!!!
I need insert records into table1 if condition in table2 is met. The insert values include constant values and values that are selected from table2. How can I do it?
There are 10 fields in table1, 5 fields are constant value, 5 fields need to be selected from table2 when condition, such as table2.status ='N' met. So if table2.status ='N', then insert a record into table1 with 10 fields.
if all values are from table2, then I will do:
Insert into table1(f1,f2,f3,f4,f5...f10)
select f1,f2...f10
from table2
where table2.status ='N'
But I need to set values for f1 to f5 which are not select from table2, they are constant. How can I set the values at the same time when select others. I am working on SQL server 2008.
Thank you so much for any helps and suggestions!!!