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)
 Need help with concatenatiing column in SQL

Author  Topic 

mldardy
Starting Member

13 Posts

Posted - 2009-06-22 : 20:28:14
In the query below, I am trying to show the customer once for each rate code. Meaning there is 1 customer but they may have 15 rate codes for example. The problem now is on the GROUP BY I get an error that asks for the dratecode to be included in the GROUP BY.

How do I fix this query so when I run it shows the the customer one time with each dratecode in a concatenated string separated by commas.



SELECT a.HOUSE, a.ACCTCORP, a.CUST, { fn CONCAT(b.DRATECODE, ',') } AS Expr1
FROM CUST_TABLE a INNER JOIN RC_TABLE b ON a.ACCTCORP = b.ACCTCORP
GROUP BY a.HOUSE, a.ACCTCORP, a.CUST,
ORDER BY a.HOUSE DESC

masoudsafi
Starting Member

2 Posts

Posted - 2009-06-22 : 20:40:48
try this:

SELECT DISTINCT ACCTCORP FROM RC_TABLE

Then you can do an inner join to your CUST_TABLE to obtain additional columns that you need. If you are using SQL 2005 Management Studio, you may want to use the Query Designer.

Good luck.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-22 : 21:29:28
see concatenate records without UDF


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -