34,576
社区成员
发帖
与我相关
我的任务
分享
--> --> (Roy)生成測試數據
if not object_id('表1') is null
drop table 表1
Go
Create table 表1([列名编号] int,[名称] nvarchar(1))
Insert 表1
select 1,N'a' union all
select 2,N'b' union all
select 3,N'c' union all
select 4,N'd' union all
select 5,N'e'
Go
--> --> (Roy)生成測試數據
if not object_id('表2') is null
drop table 表2
Go
Create table 表2([编号] nvarchar(3),[1] nvarchar(1),[2] nvarchar(1),[3] nvarchar(1),[4] nvarchar(1),[5] nvarchar(1))
Insert 表2
select N'001',N'r',N'r',N'd',N's',N's' union all
select N'002',N'd',N'd',N'f',N'f',N'v'
Go
declare @s nvarchar(1000)
set @s='select [编号] '
Select @s=@s+',' +quotename([列名编号])+' as '+quotename([名称])from 表1
print @s
exec(@s+' from 表2')
/*
编号 a b c d e
001 r r d s s
002 d d f f v
*/