行数据转换为字符串 [英] a row data convert into a string
本文介绍了行数据转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,专家,
感谢您的关注.
我可以将行转换为字符串/nvarchar变量吗?
像:
ID名称loc joindate有效
1 AB KOL 2012-03-22 true
我要这个
喜欢
1#AB#KOL#2012-03-22 @ true.
请帮忙.
在此先感谢.
Hi Experts,
Thanks for attention.
Can I convert a row into a string/nvarchar variable.
like:
id name loc joindate active
1 AB KOL 2012-03-22 true
I want to this
like
1#AB#KOL#2012-03-22@true.
please help.
Thanks in Advance.
推荐答案
萨哈...
请尝试以下查询.
Hi Saha...
Please try the below query.
select top 1 [name]+' #'+[product]+' #'+CONVERT(varchar,[amount],0)+'@'+convert(varchar,[sales ID])
from sales
它将为您提供帮助.
It will help you.
尝试此操作
try this
SELECT TOP 1
CONVERT(varchar(MAX),id) +'#'+ name + '#' + loc + '#' +
CONVERT(varchar(MAX),getdate())
+ '@' + CASE WHEN active = 1 THEN 'true' ELSE 'false' END
FROM dbo.Yourtable
select Top 1
COALESCE(CONVERT(VARCHAR,datetest.ID),'blank')+'#'+
COALESCE(Name,'blank')+'#'+
COALESCE(loc,'blank')+'#'+
COALESCE(convert(varchar,joindate),'blank')+'#'+
COALESCE(case when convert(varchar,active)=1 then 'true' else 'false' end,'blank')
from tbl_emp
效果很好
This is working perfectly
这篇关于行数据转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文