why does this code below return a single row of combined column names, when I would expect 3 rows?
----------------
create table PERM_TABLE (
COLUMN_A varchar(1) ,
COLUMN_B varchar(1) ,
COLUMN_C varchar(1) )
declare @select_values varchar(1000)
set @select_values = null
-- Get the Insert/Select columns
select @select_values = coalesce(@select_values + ', ', '') + '[' + column_name + ']'
from information_schema.columns
where table_name = 'PERM_TABLE'
select @select_values
----
2007-03-21
19:28:34
·
3 answers
·
asked by
Bendaberg
2
in
Computers & Internet
➔ Programming & Design
Thanks Guys - I'm still missing something here - I don't see how/where that call is combining three rows from information_schema.columns, into 1 single concatenated row.
i.e. why does the code snippet below not work in the same way?
----------------
create table #temp (
TABLE_NAME varchar(50) null ,
COLUMN_LIST varchar(1000) null )
insert into #temp ( TABLE_NAME ) select 'PERM_TABLE'
update #temp
set COLUMN_LIST = coalesce(COLUMN_LIST + ', ', '') + '[' + column_name + ']'
from #temp t
inner join [information_schema].[columns] i on t.table_name = i.Table_Name
Thanks!
2007-03-21
19:45:08 ·
update #1