September 8, 2010 at 9:25 am
hi to all is it possible to do like this
DECLARE @Tbl AS TABLE (Mid INT,Sid INT, Val VARCHAR(10))
INSERT INTO @Tbl VALUES(1,1,'A')
INSERT INTO @Tbl VALUES(1,2,'A')
INSERT INTO @Tbl VALUES(1,3,'D')
INSERT INTO @Tbl VALUES(1,4,'X')
INSERT INTO @Tbl VALUES(2,1,'A')
INSERT INTO @Tbl VALUES(2,2,'A')
INSERT INTO @Tbl VALUES(2,3,'C')
INSERT INTO @Tbl VALUES(2,4,'D')
SELECT * FROM @Tbl
i need a result LIKE this
1 A,D,X
2 A,C,D
is it possible
Every rule in a world of bits and bytes, can be bend or eventually be broken
MyBlog About Common dialog control
A Visualizer for viewing SqlCommand object script [/url]
September 8, 2010 at 9:36 am
What would be your expected output for
INSERT INTO @Tbl VALUES(1,1,'A')
INSERT INTO @Tbl VALUES(1,2,'D')
INSERT INTO @Tbl VALUES(1,3,'X')
INSERT INTO @Tbl VALUES(1,4,'A')
September 8, 2010 at 10:35 am
Don't ask me exactly how this works, but a Big Hat Tip to Jeff Moden here :cool::
SELECT t1.Mid,
STUFF((SELECT DISTINCT(',' + t2.Val)
FROM @Tbl t2
WHERE t1.Mid = t2.Mid FOR XML PATH('')),1,1,'')
FROM @Tbl t1
GROUP BY t1.Mid
see http://www.sqlservercentral.com/articles/Test+Data/61572/
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
September 9, 2010 at 7:15 am
that's Really great i read that article such a wonder full information lot of thanks
Every rule in a world of bits and bytes, can be bend or eventually be broken
MyBlog About Common dialog control
A Visualizer for viewing SqlCommand object script [/url]
September 9, 2010 at 8:29 am
thava (9/9/2010)
that's Really great i read that article such a wonder full information lot of thanks
'Glad to help - thanks!
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply