3

I want to Insert records from one table into another like

Insert into table2([column1], [column2], [column3])  
select column1, column2, column3  
from table1

however instead of all three values coming from table one I would like to insert a specific value stored in a variable. I Think it would look something like this

declare @variable int
set @variable = 2

Insert into table2([column1], [column2], [column3]) 
select @variable, column2, column3  
from table1

In this way every row from table one would be inserted into table two with the only difference being every value in column one would be 2.

Is this possible without using a cursor?

2 Answers 2

8

The way you've done it is correct:

INSERT INTO table2 ([column1], [column2], [column3])
SELECT @variable, column2, column3
FROM table1
1

what you have should work just fine

declare @variable int 
set @variable = 2

Insert into table2([column1], [column2], [column3]) 
select @variable, column2, column3
from table1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.