August 17, 2009 at 3:54 am
Hi Friends,
Need small requirement
CREATE TABLE MST_GENDER
(YR INT,
GENDER_DESC VARCHAR(100)
)
INSERT INTO MST_GENDER
SELECT 2003,'M'
UNION ALL
SELECT 2003,'F'
UNION ALL
SELECT 2004,'M'
UNION ALL
SELECT 2004,'F'
UNION ALL
SELECT 2004,'O'
-- NOW I WOULD LIKE TO ASSIGN DISTINCT VALUES OF GENDER IN A VARIABLE WITH COMMA SEPARTED
-- ALL GENDERS
DECLARE @values VARCHAR(500)
SELECT @values = ISNULL(@values+',','')+GENDER_DESC FROM MST_GENDER
SELECT @values
--M,F,M,F,O
i tried with the below but giving different output
DECLARE @values VARCHAR(500)
SELECT distinct @values = ISNULL(@values+',','')+GENDER_DESC FROM MST_GENDER
SELECT @values
-- O
Thanks in Advance
August 17, 2009 at 3:58 am
This should help you along
http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/
August 17, 2009 at 4:12 am
hI,
Also Try this
DECLARE @values VARCHAR(500)
SELECT @values = coalesce(@values+',','')+GENDER_DESC
FROM MST_GENDER
GROUP BY GENDER_DESC
SELECT @values
August 17, 2009 at 7:56 pm
Hi Arun,
Thank You.:-)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply