行转列同时插入字符串问题
时间:2011-12-16
来源:互联网
SQL code
create table #temp (en nvarchar(30)) insert into #temp values('DuanTou') insert into #temp values('DaiQi') /*想要的结果 isnull(DuanTou,0)+isnull(DaiQi,0) */
作者: chirea 发布时间: 2011-12-16
什么意思
作者: pengxuan 发布时间: 2011-12-16
SQL code
---------------------------------------------------- /*如何将一列中所有的值一行显示 数据源 a b c d e 结果 a,b,c,d,e */ create table tb(col varchar(20)) insert tb values ('a') insert tb values ('b') insert tb values ('c') insert tb values ('d') insert tb values ('e') go --方法一 declare @sql varchar(1000) set @sql = '' select @sql = @sql + t.col + ',' from (select col from tb) as t set @sql='select result = ''' + left(@sql , len(@sql) - 1) + '''' exec(@sql) /* result ---------- a,b,c,d,e, */ --方法二 declare @output varchar(8000) select @output = coalesce(@output + ',' , '') + col from tb print @output /* a,b,c,d,e */ ---方法三 declare @s varchar(1000) select @s=isnull(@s+',' , '')+col from tb select @s /* a,b,c,d,e */ drop table tb -------------
作者: fredrickhu 发布时间: 2011-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28