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.
| Author |
Topic |
|
roizanladiero
Starting Member
5 Posts |
Posted - 2011-09-09 : 23:29:25
|
| declare @temp varchar(1000)select @temp=(case when @temp is null then '' else @temp + ',' end)+''''+column_name+'''' from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '##BCP_Results' --PRINT @tempINSERT INTO ##BCP_Resultsexec ('select' + @temp)select * from ##BCP_Results--The result is Server: Msg 170, Level 15, State 1, Line 1--Line 1: Incorrect syntax near 'select'.Please help!Thank youRoizan Ladiero |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-10 : 00:35:17
|
| are you trying to insert column names or are you trying to insert data from columns?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
roizanladiero
Starting Member
5 Posts |
Posted - 2011-09-11 : 21:42:41
|
| @visakh16: I tried to insert column names. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-12 : 01:01:12
|
i'm assuming you want a single row in ##BCP_Results with entire column list coming as comma separated values. in that case what you want is belowdeclare @temp varchar(1000)select @temp=case when @temp is null then '' else @temp + ',' end +column_namefrom INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '##BCP_Results' PRINT @tempINSERT INTO #BCP_Resultsexec ('select' + ''''+ @temp +'''' )------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|