Thursday, March 17, 2005

Display the particular column value in one row

If u wanna display the particular column value in one row with Comma separated
The idea behind of that is only depends on self join

DECLARE @str VARCHAR(8000)
SELECT @str = COALESCE(@str+',','')+(SELECT UserID FROM UserMaster UM1 WHERE UM1.UserPKID = UM2.UserPKID ) FROM usermaster UM2
SELECT @str

The Result like this
------------------------
SHANKAR,HARI,SELVAM,RAMESH,DHINA,ASIF,RAJESH,SIVA,AMBRISH,RAMU

No comments: