SQL 语句-列名与字符串的转换
两个TABLE.请问用SQL实现从TABLE1得到TABLE2这样的结果?TABLE1:ROLEP1P2AYBYCYTABLE2:POSITONROLEP1AP1BP2C...
两个TABLE.请问用SQL实现从TABLE1得到TABLE2这样的结果?
TABLE1:
ROLE P1 P2
A Y
B Y
C Y
TABLE2:
POSITON ROLE
P1 A
P1 B
P2 C
set @sql1='insert into role (role,position) select role,'''+@name+''' FROM TEST where '+@name+' is not null'
--select * from test where p1 is not null
exec(@sql1)
set @i=@i+1
end
问题已经解决..哎,都怪自己太笨,1个字符串与列名的在转换没搞清楚..谢谢大家的回答. 展开
TABLE1:
ROLE P1 P2
A Y
B Y
C Y
TABLE2:
POSITON ROLE
P1 A
P1 B
P2 C
set @sql1='insert into role (role,position) select role,'''+@name+''' FROM TEST where '+@name+' is not null'
--select * from test where p1 is not null
exec(@sql1)
set @i=@i+1
end
问题已经解决..哎,都怪自己太笨,1个字符串与列名的在转换没搞清楚..谢谢大家的回答. 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询