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)
 Concatenating column values for each uniqueid

Author  Topic 

mgandra
Starting Member

15 Posts

Posted - 2005-11-06 : 11:12:14
I have a table like the below:
OrderId QueueId Template Subject RecdDtim SentDtim
1 1 TEM1 Sub1 11/3/2005 8:10:10 11/3/2005 9:00:15
1 2 TEM3 Sub2 11/3/2005 10:25:45 11/3/2005 10:40:35
2 3 TEM1 Sub2 11/3/2005 11:45:35 11/3/2005 12:00:00
1 4 TEM2 Sub3 11/4/2005 10:25:00 11/4/2005 10/30:00
2 5 TEM3 Sub3 11/4/2005 11:56:00 11/4/2005 12:00:00


I want to concatenate Template, Subject and SentDtim column values for each order and display results like the below:

OrderId Email
1 TEM1,Sub1,11/3/2005 | TEM3,Sub2,11/3/2005|TEM2,Sub3,11/4/2005
2 TEM1,Sub2,11/3/2005 | TEM3, Sub3, 11/4/2005

Please help me how to write the sql query in SQL Server 2000 to insert the results in the above format into a temporary table so that I can join that temp table with another table on orderid column and bind the result set to a datagrid in .aspx (asp.net)page.
Any help will be highly appreciated.

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-06 : 13:55:56
create table #a (orderid int , s varchar(4000))
insert #a select orderid, min(QueueId + [Template Subject] + convert(varchar(8),SentDtim,112)) from tbl group by orderid

while @@rowcount > 0
insert #a select orderid, min(tbl.QueueId + tbl.[Template Subject] + convert(varchar(8),tbl.SentDtim,112))
from tbl
where #a.orderid = tbl.orderid
and #a.s < tbl.QueueId + tbl.[Template Subject] + convert(varchar(8),tbl.SentDtim,112))


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-07 : 01:35:54
Refer this also
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -