问题描述
大家好,
我保存了这样的值
1 AndhraPradesh 22 Vizianagaram Denkada
1 AndhraPradesh 22 Vizianagaram Bhoghapuram
1 AndhraPradesh 22 Vizianagaram Pusapatirega
1 AndhraPradesh 21 Visakhapatnam Bheemunipatnam
1安得拉邦21维沙卡帕特南阿拉库山谷
1安得拉邦21 Visakhapatnam Anakapalle
1安得拉邦21 Visakhapatnam Gajuwaka
1安得拉邦21 Visakhapatnam Chodavaram
但是我想要这样的输出
1 AndhraPradesh 22 Vizianagaram Denkada
博加普拉姆
Pusapatirega
21维沙卡帕特南荒原谷
加朱瓦卡
有可能吗?
谁能解决这个问题
谢谢与问候
Hari
Hi All,
I saved Values like this
1AndhraPradesh22Vizianagaram Denkada
1AndhraPradesh22VizianagaramBhoghapuram
1AndhraPradesh22VizianagaramPusapatirega
1AndhraPradesh21VisakhapatnamBheemunipatnam
1AndhraPradesh21VisakhapatnamAraku Valley
1AndhraPradesh21VisakhapatnamAnakapalle
1AndhraPradesh21VisakhapatnamGajuwaka
1AndhraPradesh21VisakhapatnamChodavaram
But i want output like this
1 AndhraPradesh 22 Vizianagaram Denkada
Bhogapuram
Pusapatirega
21 Visakhapatnam Araku Valley
Gajuwaka
is it possible r not?
can any one solve it plz
Thanks & Regards
Hari
推荐答案
SELECT p.ASSIGNNUM,p.DESC,p.STARTDATE,LEFT(el.EmpList,LEN(el.EmpList)-1)
FROM #TableParent p
CROSS APPLY (SELECT EMPLOYEENUM + ',' AS [text()]
FROM #TableChild
WHERE ASSIGNNUM =p.ASSIGNNUM
FOR XML PATH('')) el(EmpList)
显然,您需要对其进行修改以适合您的需求,但最终结果将是最后一列中用逗号分隔的值列表.
Obviously you would need to modify it to fit your needs but the end result would be a comma-delimited list of values in the last column.
Select Distinct o.State, o.City,
(
Select I.Mandal + ', ' From Mandal I
Where I.StateID = o.StateID and I.CityID = o.CityID
For XML Path('')
) [Combined Data]
from Country O
这篇关于如何从SQL数据库中获取单列名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!