question

IT1234 avatar image
IT1234 asked

crosstab queries

cross tab query item rcvd_date x 1/1/2010 x 2/2/2010 x 3/3/2010 y 1/1/2010 y 2/4/2010 RESULT SHOULD BE X 1/1/2010 2/2/2010 3/3/2010 Y 1/1/2010 2/4/2010 how to go about this?? thank you
t-sqlcross-tab
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
For starters, look at the [PIVOT][1] statement. Then have a trawl around this site - there are other questions which go into this. For example, [this question][2] looks at pivot & dynamic SQL. [1]: http://msdn.microsoft.com/en-us/library/ms177410.aspx [2]: http://ask.sqlservercentral.com/questions/3387/dynamic-pivot-with-multiple-aggregates
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Phil Factor avatar image
Phil Factor answered
It is difficult to tell from the example whether you want to have a separate column for each day of the month with a date in it if the item was received, or whether you merely want to concatenate the results in a list for each item, the list being the dates when it was received. If the latter, then this article here will tell you how to do it. [ http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/][1] [1]: http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Phil Factor avatar image Phil Factor commented ·
Oops, I forgot about having to do URLs
1 Like 1 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
@WilliamD - you're a brave man, editing the great Phil Factor's content! I still remember feeling deeply embarrassed at overtaking him (karmically speaking) here...
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
only changed the link to be clickable - don't think he'll set the dogs on me for that.... what was that noise?!
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
happens to me all the time.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.