TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
priyanka
NA
215
123.2k
Stuff Function In Sql Server
Feb 25 2018 11:34 PM
My Table Structure is like this
ClassId ClassNm
1 1
2 2
3 3
SubjectId subjectNm
001 Hindi
002 ENGLISH
003 Math
ClassId SubjectId
1 001
1 002
1 003
2 001
2 002
3 003
I want the output in following format
classId Subject
1 001,002,003
My query is something like this,
Select cs.ClassId,cl.ClassNm,
STUFF((Select ','+ sc.Subject from dbo.Class_Subject cs,dbo.Class cl,dbo.Subject sc
where cl.ClassId=cs.ClassId and sc.SubCode=cs.SubCode FOR XML PATH('')) ,1,1,' ')
as Subject
from dbo.Class_Subject cs,dbo.Class cl,dbo.Subject sc where cl.ClassId=cs.ClassId and
sc.SubCode=cs.SubCode Group by cs.ClassId,cl.ClassNm
But I am not getting the proper result.
Plz suggest,what I am doing wrong.
Reply
Answers (
2
)
In sql substract next value from previous value and check
What is the alternative of Identity in Sql Server ?