设为首页 加入收藏

TOP

MSSql表列拼接成字符串简析
2014-11-24 02:57:12 来源: 作者: 【 】 浏览:2
Tags:MSSql 拼接 字符串 简析
MSSql表列拼接成字符串简析
将表列拼接成字符串。闲话不多说切入正题,看代码:
[sql]
select STUFF(
REPLACE( www.2cto.com
REPLACE(
(select fieldName as pc from cj_datadictionary as N
join [CSD_ORD_PayMent] on costsid=fieldCode and fieldType='OP' where memberid=72157 and groupID='201205DD2119416553' and [Expenditure]>0
FOR XML AUTO),'',''
),1,1,''
)
第一步:将表转化为xml格式
[sql]
select fieldName as pc from cj_datadictionary as N
join [CSD_ORD_PayMent] on costsid=fieldCode and fieldType='OP'
where memberid=72157 and groupID='201205DD2119416553' and [Expenditure]>0
FOR XML AUTO www.2cto.com
第二步:替换
第三步:替换 "/> 注:每项都会以“<表 字段”开始,以“ "/>”结束
[sql]
select REPLACE(REPLACE((select fieldName as pc from cj_datadictionary as N
join [CSD_ORD_PayMent] on costsid=fieldCode and fieldType='OP'
where memberid=72157 and groupID='201205DD2119416553' and [Expenditure]>0
FOR XML AUTO),'','')
最后使用:STUFF() 函数作用:删除指定长度的字符,并在指定的起点上插入另外的字符串
[sql]
select STUFF(
REPLACE( www.2cto.com
REPLACE(
(select fieldName as pc from cj_datadictionary as N
join [CSD_ORD_PayMent] on costsid=fieldCode and fieldType='OP' where memberid=72157 and groupID='201205DD2119416553' and [Expenditure]>0
FOR XML AUTO),'',''
),1,1,''
)
作者 zhengdjin
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇postgresql安装pg_stat_statements 下一篇mssql字符串移除指定长度字符

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·进入Linux世界大门的 (2025-12-24 14:51:47)
·Download Linux | Li (2025-12-24 14:51:44)
·Linux 指令初探:开 (2025-12-24 14:51:41)
·TCP连接失败的原因与 (2025-12-24 14:19:27)
·TCP Sever模式与TCP (2025-12-24 14:19:24)