实现VFP中COPY STRUCTURE EXTENDED功能的MSSQLServer怎么写?
一个旧表中都是人名记录,新表中要把每个人作为一个字段。
多谢!
------解决方案--------------------
------解决方案--------------------
- SQL code
DECLARE @col VARCHAR(max)SELECT @col=ISNULL(@col+',','')+QUOTENAME([name]) FROM [tb] GROUP BY [name]EXEC('selcet * into newtable from(SELECT * FROM [tb] PIVOT(MAX([id]) FOR [name] IN ('+@col+') ) piv) as t where 1=2')SELECT * FROM newtable