0
在此應答here,人開始了與下面的代碼塊:如何一個nvarchar被填充在SELECT語句
-- Build list of cols we want to unpivot (skip PID & UID)
declare @cols nvarchar(max)
select @cols = coalesce(@cols+N',', N'') + quotename(c.name) from syscolumns c
inner join sysobjects o on c.id = o.id and o.xtype = 'u'
where o.name = 'MyTable' and c.name not in ('PID', 'UID') order by c.colid
我試圖環繞我的頭@cols如何填充以這種方式。當我取出變量定義@cols =
時,它返回一個列表。當我拿出coalesce()
並且只輸入@cols+N','
時,select @cols
就是空。
任何人都可以點我的方向,我可以找出這是如何工作的?