我试过了我最好但我无法获得我的例外输出 [英] I Tried My Best But I Could Not Get My Excepted Output
问题描述
我的查询如下
选择教师,STUFF(
(选择','+ ltrim(rtrim([课程]) )+' - S'+ ltrim(rtrim([Session]))来自Tb_Sch_Time_Table sch
其中sch.Schdate = sch1.Schdate和sch.Faculty = sch1.Faculty
FOR XML PATH(''))
,1,1,'')+')'作为来自Tb_Sch_Time_Table的计划sch1
group by schdate,Faculty >
我把上面的查询视为如下
选择不同的教师,
stuff((选择','+作为Msg从Vw_Presea_Sch_Send_SMS vw1调度,其中vw1.faculty = vw2.faculty FOR XML PATH('')),1,6,'')作为msg
来自Vw_Presea_Sch_Send_SMS vw2
视图名称是Vw_Presea_Sch_Send_SMS
当我执行上述操作时查询输出如下
8月26日(B Tech 1-S3,B Tech 1-S4)< msg>,8月28日(ETO-S3,ETO-S4)
但是我想要他正确输出如下
8月26日(B Tech 1-S3,B Tech 1-S4)8月28日(ETO-S3,ETO-S4)
>
获得以上输出我在上面的查询中所做的更改是什么。
My Query as follows
select Faculty,STUFF(
(select ','+ ltrim(rtrim([Course])) +'-S'+ltrim(rtrim([Session])) from Tb_Sch_Time_Table sch
where sch.Schdate = sch1.Schdate and sch.Faculty = sch1.Faculty
FOR XML PATH(''))
,1,1,'')+')' as Schedule from Tb_Sch_Time_Table sch1
group by schdate,Faculty
I put the above query in view as follows
select distinct faculty,
stuff((select ',' + schedule as Msg from Vw_Presea_Sch_Send_SMS vw1 where vw1.faculty = vw2.faculty FOR XML PATH('')),1,6,'') as msg
from Vw_Presea_Sch_Send_SMS vw2
Views name is Vw_Presea_Sch_Send_SMS
When i execute the above query output as follows
Aug 26 (B Tech 1-S3,B Tech 1-S4)<msg>,Aug 28 (ETO-S3,ETO-S4)
But i want the correct output as follows
Aug 26 (B Tech 1-S3,B Tech 1-S4) Aug 28 (ETO-S3,ETO-S4)
for that getting a above output what is the changes i have to made in above query.
推荐答案
更改来自
Change From
select distinct faculty,
stuff((select ',' + schedule as Msg from Vw_Presea_Sch_Send_SMS vw1 where vw1.faculty = vw2.faculty FOR XML PATH('')),1,6,'') as msg
from Vw_Presea_Sch_Send_SMS vw2
要
To
select distinct faculty,
stuff((select ' ' + schedule from Vw_Presea_Sch_Send_SMS vw1 where vw1.faculty = vw2.faculty FOR XML PATH('')),1,0,'') as MSG
from Vw_Presea_Sch_Send_SMS vw2
希望这有助于
Hope this helps
这篇关于我试过了我最好但我无法获得我的例外输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!