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 2005 Forums
 Transact-SQL (2005)
 merge rows by SQL SELECT command

Author  Topic 

dalibor
Starting Member

21 Posts

Posted - 2009-05-05 : 05:44:09
Hi all,

I have this table data:
(example)

INR ATTRIBUT
------------------
120212 SA
120212 D
120212 N

How merge rows with identical INR?
Required result:

INR MERGE_ATTRIBUT
------------------------
120212 SA,D,N

Thanks for any idea.

Dalibor

mailsomani
Starting Member

4 Posts

Posted - 2009-05-05 : 05:54:21
SELECT DISTINCT A.INR,Attrbute FROM test1 A
CROSS APPLY
(
-- Now get all the articles for each author in XML
SELECT Attrbut + ', ' FROM test1 B WHERE A.INR = B.INR
FOR XML Path('')
) AS C (Attrbute)


Pawansomani
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-05 : 06:33:05
DECLARE @t TABLE (INR INT,ATTRIBUT VARCHAR(6))
INSERT INTO @t SELECT 120212 , 'SA' UNION ALL
SELECT 120212, 'D' UNION ALL
SELECT 120212, 'N'

SELECT DISTINCT INR,STUFF((SELECT ','+ ATTRIBUT FROM @t WHERE INR = t.INR FOR XML PATH('')),1,1,'')
FROM @t t

and u can use function too this
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-05 : 06:33:25
Also refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

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

dalibor
Starting Member

21 Posts

Posted - 2009-05-05 : 10:01:22
Thanks to Madhivanan, it is work.
Be sorry, I'll must solve this problem in Oracle platform :-( , i need change my plan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-05 : 10:13:48
quote:
Originally posted by dalibor

Thanks to Madhivanan, it is work.
Be sorry, I'll must solve this problem in Oracle platform :-( , i need change my plan


Post your question at Oracles forums such as www.orafaq.com and www.dbforums.com

Madhivanan

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

- Advertisement -