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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Thought it was very easy query

Author  Topic 

ajay
Starting Member

34 Posts

Posted - 2004-08-18 : 18:24:22
Hello Gurus,

I have a table whose structure is like this

Column A ColumnB
A T
B T
B X
A X
A Y
B Y

Using Some query I want to return record in a string format
something like
A;B for column A and T;X;Y for column B With out using Two temporary table for each column.
I tried using CoalESC function but it gives A;B;B;A;A;B etc. As you can see I need distinct values in my string..

Sincerly

ajay

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2004-08-18 : 18:36:47
Use use "DISTINCT" to get values only once and "ORDER BY" to get it sorted

mk_garg
Go to Top of Page

ajay
Starting Member

34 Posts

Posted - 2004-08-18 : 19:06:16
quote:
Originally posted by mk_garg20

Use use "DISTINCT" to get values only once and "ORDER BY" to get it sorted

mk_garg


For Column A in a string I used
SELECT @ColA=COALESCE(@ColA+'','')+ ColumnA from Table

Where do i use distinct here?

Thanks
Ajay


ajay
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-08-18 : 19:29:38
Have a look at the following article:

http://www.sqlteam.com/item.asp?ItemID=11021
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2004-08-19 : 02:14:26
Try this

SELECT @ColA=COALESCE(@ColA+'','')+ ColumnA from
(SELECT DISTINCT columnA from Table) A



mk_garg
Go to Top of Page
   

- Advertisement -