October 20, 2005 at 11:21 am
Is this possible within TSQL?
InvoiceHeader schema / sample data
ClientID | InvoiceDate | InvoiceTotal |
{guid1} | 1/1/2005 | 1500 |
{guid1} | 2/1/2005 | 1250 |
{guid1} | 3/1/2005 | 995 |
{guid2} | 1/1/2005 | 500 |
{guid2} | 3/1/2005 | 750 |
I want to return a dataset where the distinct InvoiceDate values are the column names with the InvoiceTotal as the column value
eg:
ClientID | 1/1/2005 | 2/1/2005 | 3/1/2005 |
{guid1} | 1500 | 1250 | 995 |
[guid2} | 500 | NULL | 750 |
October 20, 2005 at 11:25 am
Sure, but you're going to have to use a stored proc and dynamic SQL.
Unless you know in advance what the columns are always going to be.
October 20, 2005 at 11:27 am
No, the invoicedate values are variable.
October 20, 2005 at 11:31 am
Answered many times and many ways. Try a search on this site for:
"variable column names"
October 20, 2005 at 11:34 am
Thanks, will do.
[Edit] - In reviewing those as well as others, none are quite the same in that my column names will be totally variable, so the traditional Cross-tab methodology of using a CASE statement with a defined column name does not apply.
Seems to be what's apparently referred to as a Dynamic Crosstab query. I'm researching that now.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply