Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql query problem

Author  Topic 

keyursoni85
Posting Yak Master

233 Posts

Posted - 2008-05-09 : 03:30:34
Select j.AdminID, g.groupname from Admins j
LEFT OUTER JOIN dbo.AdminGroup AS jg ON j.AdminID = jg.AdminID
INNER JOIN [Group] AS g ON g.GroupId = jg.GroupId
WHERE (j.isDeleted = 0) AND ISNULL(j.IsSystemUser,0) = 0

Result of above query
---------------------
AdminID groupname
--------------------------
6 PS
6 Admins
4 PS2
28 PSR
28 Admins
26 Admins


I want output like this...
------------------------

---------------------
AdminID groupname
--------------------------
6 PS, Admins
4 PS2
28 PSR, Admins
26 Admins

Please help

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-09 : 03:44:53
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53293

Triple post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102536
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102537


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

eralper
Yak Posting Veteran

66 Posts

Posted - 2008-05-09 : 04:01:19
Hello keyursoni85,

Here is a t-sql script that works fine on SQL2005


select AdminID,
STUFF(
(
Select ',' + g.groupname
from Admins j
LEFT JOIN AdminGroup AS jg ON j.AdminID = jg.AdminID
INNER JOIN [Group] AS g ON g.GroupId = jg.GroupId
WHERE (j.isDeleted = 0) AND ISNULL(j.IsSystemUser,0) = 0
and j.AdminID = Admins.AdminID
FOR XML PATH('')
), 1, 1, '') as groups
FROM Admins


You can read an article for such situations at [url]http://www.kodyaz.com/articles/concatenate-using-xml-path.aspx[/url]

I hope you will find this helpful,
Eralper


-------------
Eralper
http://www.kodyaz.com
Go to Top of Page

keyursoni85
Posting Yak Master

233 Posts

Posted - 2008-05-09 : 11:23:49
thank you all
Go to Top of Page
   

- Advertisement -