Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Head-breaking query
Message
 
 
To
20/09/2016 19:51:22
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01641137
Message ID:
01641170
Views:
42
>>>
>>>I tried Naomi's answer. I got blank values in some of the column/row cells and couldn't figure out how to prevent that.
>>>
>>
>>I just tried her code (where she used ROW_NUMBER). It works.
>>
>>One thing...assuming I understand the result sets you're looking for - you *will* have some empty cells, unless for each day you have the same number of locations.
>>
>>In her brief example with six rows, here's the output. So I guess I don't understand why her query doesn't address it.
>>
>>
>>Sunday	        Monday
>>Loc1	        Loc3
>>Loc2	        Loc4
>>Loc5	
>>Loc6	
>>
>
>When I tried it with real data, I got something like this
>
>
>>
>>Sunday	        Monday
>>Loc1	        Loc3
>>Loc2	        Loc4
>>Loc5	
>>Loc6              Loc7	
>>
>
>On second thought- or third or fourth thought..that blank cell might be OK
>
>I'll look again

The reason you got blank rows could be that you had same location for the same day number a few times in the table (e.g. StoreCode/DayNumber is not a unique combination). That's why in my second variation I used dense_rank() instead of row_number().
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform