dbTalk Databases Forums  

Concatenate Mutiple Rows Data to Single RowColumn comma separatedData

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Concatenate Mutiple Rows Data to Single RowColumn comma separatedData in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
chintu4uin@gmail.com
 
Posts: n/a

Default Concatenate Mutiple Rows Data to Single RowColumn comma separatedData - 01-25-2010 , 05:01 AM






Hi friends I m using SQL 2005 I want to concatenate multiple rows into
single row with comma separated. I tried using for XML and all but
what I m looking for I m not getting that My Table structure:-

Table A
SOANo | TaxOrderDisplay | TaxDescription|
2009001 | 1 | Excise
2009001 | 2 | Edu Cess on Exc
2009001 | 3 | S.HS.EduCess-Ex
2009002 | 1 | Excise
2009002 | 2 | Edu Cess on Exc
2009002 | 3 | S.HS.EduCess-Ex
2009002 | 4 | VAT
2009003 | 1 | Excise
2009003 | 2 | Edu Cess on Exc
2009003 | 3 | S.HS.EduCess-Ex
2009003 | 4 | VAT
2009003 | 5 | Octori

Output Should
-----------------------
2009001 | Excise,Edu Cess on Exc,S.HS.EduCess-Ex,
2009002 | Excise,Edu Cess on Exc,S.HS.EduCess-Ex,VAT,
2009003 | Excise,Edu Cess on Exc,S.HS.EduCess-Ex,VAT,Octori

but I m getting output like this
-------------------------------------------
2009001 | Edu Cess on Exc,Excise,S.HS.EduCess-Ex,
2009002 | Edu Cess on Exc,Excise,S.HS.EduCess-Ex,VAT,
2009003 | Edu Cess on Exc,Excise,Octroi,S.HS.EduCess-Ex,VAT,

I m using the below query
--------------------------------------------------------------------------------------------------
SELECT
SOAItemTaxSOANo,
STUFF(CAST((SELECT distinct TaxDescription + ',' FROM vwSOAPreview
t2
WHERE t2.SOAItemTaxSOANo =
vwSOAPreview.SOAItemTaxSOANo
FOR XML PATH(''), TYPE) AS VARCHAR(8000)), 1, 0, '')
AS 'TaxDescriptions'
FROM
vwSOAPreview
GROUP BY
SOAItemTaxSOANo
--------------------------------------------------------------------------------------------------
My problem is that Tax description should come in order of their
TaxOrderDisplay ID but I m getting it in alphabetical order which I
dont want.

Please frnd reply u r suggestion for the same where I m going wrong...

Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Concatenate Mutiple Rows Data to Single RowColumn comma separated Data - 01-25-2010 , 06:45 AM






On Mon, 25 Jan 2010 03:01:17 -0800 (PST), chintu4uin (AT) gmail (DOT) com wrote:

(snip)

Answered in microsoft.public.sqlserver.programming.

Please don't post the same question to multiple newsgroups.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.