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)
 Query for Two/More ROW Combind in one ROW

Author  Topic 

aiman
Starting Member

18 Posts

Posted - 2007-06-21 : 14:07:14
Suppose I have a Table where Data are inserted like this way

UnID QUERY
1011 VASINFO
1012 TEXINFO
1013 GENERAL QUERY
1013 BILL INFO
1014 FNF INFO
1014 NETWORK PROB
1014 TEST CALL

Now I want to write a quary which will show this data like

UnID QUERY
1011 VASINFO
1012 TEXINFO
1013 GENERAL QUERY,BILL INFO
1014 FNF INFO,NETWORK PROB,TEST CALL
1015 SIM DeActivate
1016 TEST CALL

and so on...
PLEASE Help me ASAP....

AIMAN

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-21 : 14:39:25
If its not doable at the front end, you could create a function that takes in the UnID value and returns a concatenated list of Query values. Call the function in your SELECT. Caution. doing this on a huge dataset can cause performance issues.



Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

aiman
Starting Member

18 Posts

Posted - 2007-06-21 : 14:52:43
Please give me a demo script. I will be very pleased if you give me it. I need it very urgent ly
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-22 : 00:28:47
Create table tii (UnID int,QUERY varchar(50))
Insert tii
Select 1011, 'VASINFO' union all
Select 1012, 'TEXINFO' union all
Select 1013, 'GENERAL QUERY' union all
Select 1013, 'BILL INFO' union all
Select 1014, 'FNF INFO' union all
Select 1014, 'NETWORK PROB' union all
Select 1014, 'TEST CALL'

Create function fn_concat(@id int)
returns varchar(200)
begin
Declare @concat varchar(200)
Select @concat = Coalesce(@concat+',', '') + QUERY
from tii
where UnID = @id
Return @concat
End


Select distinct UnID, dbo.fn_concat(UnID)
From tii

--------------------------------------------------
S.Ahamed
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-22 : 09:01:20
As said if possible do it in fornt end (if you use it)
Also refer this to know for more explanations
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

aiman
Starting Member

18 Posts

Posted - 2007-06-22 : 13:08:03
Thank you lots... Really it will be healfull for me.....
Go to Top of Page
   

- Advertisement -