我有一个TSQL,想要修改select语句来创建表并插入所选命令。
set @query = N'SELECT ' + @cols + N' **create table tablename (insert into**
from
(
select substring, Field_Name,
rn = row_number() over(partition by field_name order by fieldnumber)
from bear_crossjoin
) x
pivot
(
max(substring)
for Field_Name in (' + @cols + N')
) p '
如何用粗体字母定义一个?
答案 0 :(得分:0)
怎么样:
set @query = N'SELECT ' + @cols + N' INTO databasename.schemaname.tablename
from
(
select substring, Field_Name,
rn = row_number() over(partition by field_name order by fieldnumber)
from bear_crossjoin
) x
pivot
(
max(substring)
for Field_Name in (' + @cols + N')
) p '