应用场景:
向用户表中查询出需要发短信的管理员的手机号码,拼接成字符串批量处理。
将内容转换为xml格式内容
查询语句:
SELECT substring(NewCol,0,LEN(T.NewCol)-1) AS NewPhone FROM (
(SELECT (
SELECT CASE WHEN (cellphone IS NULL OR LEN(cellphone)=0) THEN '' ELSE (cellphone + ',') END
FROM dbo.Users WHERE is_night_alarm=1 FOR XML PATH('')) AS NewCol)) AS T
结果: