variable in an insert statement
Posted on 2011-05-05
I am trying to insert a variable into an insert statement that contains a list of rows. When I attempt to put the variable in an insert statement it doesn't show up on the intellisence list, and if I just type it in I get red squiggly line. It does however show and works in the select statement. I suspect it has something to do with the parens in the insert statement. Can this be done?
Declare @cols varchar(max)
Set @cols = "the routine that builds the column list"
insert into table1(field1,field2, @cols)<-- this on doesn't work
select field1, field2, @cols <-- this one works