![]() |
|
![]() | ||
|
Subject:
mssql tsql concatenating a field into itself and/or just reporting horizontally
Category: Computers > Programming Asked by: grekenski-ga List Price: $2.00 |
Posted:
09 Nov 2002 18:26 PST
Expires: 18 Nov 2002 19:22 PST Question ID: 104372 |
Can I do the following in a single SQL statement? I have the following two tables: creditcust: customer char10 (unique key) address char30 creditpurchase: customer char10(many) item char10 I am able to report customer, address, number-of-purchases jane, elm street, 3 with tsql: select creditcust.customer,creditcust.address, count(creditpurchase.item) from creditcust join creditpurchase on creditcust.customer=creditpurchase.customer group by creditcust.customer,creditcust.address I'd like to now report every purchase item to the right seperated by semicolons limiting the total string width to 256. example customer, address, number-of-purchases, purchase details jane, elm street, 3, boots;hat;watch Thank you. |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: mssql tsql concatenating a field into itself and/or just reporting horizontally
From: mathtalk-ga on 10 Nov 2002 14:21 PST |
Hi, grekenski-ga: The short answer is no, it cannot be done in a single SQL statement. The cleanest approach would be a stored procedure with a couple of nested cursors, with the details being concatenated in the inner cursor for a specific customer (indexed by the outer cursor). regards, mathtalk-ga |
Subject:
Re: mssql tsql concatenating a field into itself and/or just reporting horizontally
From: mathtalk-ga on 10 Nov 2002 20:09 PST |
A longer answer is, yes, if you can strictly limit the possible items that are to appear in the detail list. A Transact-SQL expression could be created that uses dependent subqueries to indicate the presence of specific items in the list if they exist as customer purchases. But this is not a general solution; the query would be constructed to check only for certain pre-ordained possible items. -- mathtalk-ga |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |