November 12, 2015 at 5:40 am
Hi,
this Output
rnCustomerIDCityAmountnCount
1102996Berlin675.003
2102996Magdeburg288.002
3102996Bielefeld268.002
CustomerIDTop1CityAmountnCountTop1CityAmountnCountTop1CityAmountnCount
102996Berlin675.003London288.003Paris268.003
Thanks
Regards
Nicole
November 12, 2015 at 5:48 am
You'll get a really quick response if you change this:
rn CustomerID City Amount nCount
1 102996 Berlin 675.00 3
2 102996 Magdeburg 288.00 2
3 102996 Bielefeld 268.00 2
into a CREATE TABLE... statement followed by a few inserts to populate it.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 12, 2015 at 7:26 am
November 12, 2015 at 7:30 am
The best way would be to use the CROSS TAB method, mentioned in this article : http://www.sqlservercentral.com/articles/T-SQL/63681/
Will the number of columns be limited to 3 or will it depend on the data, ie if there are 4 cities does it have to be 4 wide?
Also your Input and output data do not correspond to each other which means theres a possible typo or we are missing data, in which case we would need the full dataset.
Edit : Beat me to it Lui π
_________________________________________________________________________
SSC Guide to Posting and Best Practices
November 12, 2015 at 7:36 am
Jason-299789 (11/12/2015)
The best way would be to use the CROSS TAB method, mentioned in this article : http://www.sqlservercentral.com/articles/T-SQL/63681/Will the number of columns be limited to 3 or will it depend on the data, ie if there are 4 cities does it have to be 4 wide?
Also your Input and output data do not correspond to each other which means theres a possible typo or we are missing data, in which case we would need the full dataset.
Edit : Beat me to it Lui π
You wrote a longer post. I would have spent more time on this, but if the OP won't even care to post adequately, why would I? π
November 12, 2015 at 8:07 am
Luis Cazares (11/12/2015)
Jason-299789 (11/12/2015)
The best way would be to use the CROSS TAB method, mentioned in this article : http://www.sqlservercentral.com/articles/T-SQL/63681/Will the number of columns be limited to 3 or will it depend on the data, ie if there are 4 cities does it have to be 4 wide?
Also your Input and output data do not correspond to each other which means theres a possible typo or we are missing data, in which case we would need the full dataset.
Edit : Beat me to it Lui π
You wrote a longer post. I would have spent more time on this, but if the OP won't even care to post adequately, why would I? π
π
_________________________________________________________________________
SSC Guide to Posting and Best Practices
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply