Click here to Skip to main content
15,886,545 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have the following codes in which i wanna display the DocStatus according to their group. Suppose i have the following data:

CustName DocStatus
-------- ---------
John Single
Mary Single
John Married
Mary Divorced

my SQL statement is as below"

SQL
SELECT P.DocStatus, C.CustomerName
FROM vsCustomizationRequest.dbo.CRF_Project P, vsCustomizationRequest.dbo.CustomerList C
WHERE C.CustomerName IN (SELECT Value from funcListToTableInt2(@name, ',')) AND P.CustomerID = C.CustomerID
GROUP BY C.CustomerName


the output i want is as below:

CustName DocStatus
-------- ---------
John Single
Married
Mary Single
Divorced

how can i make it possible?

when i run the SQL statement it give me the error "Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.", i know i have to add some aggregate function or add the P.DocStatus in Group By clause but this will display different output which i dont want. Any help would be appreciated.
Posted

1 solution

Try This

SQL
SELECT
   CustName
  ,st=STUFF((SELECT ','+DocStatus FROM yourTable WHERE CustName=A.CustName FOR XML PATH('')) , 1 , 1 , '' )
FROM
   yourTable A
GROUP BY CustName



Hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900