Author |
Topic |
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-05 : 16:08:29
|
I have a ROW_NUMBER() option in my SSRS ReportExample SELECT *,ROW_NUMBER() OVER(ORDER BY Zip5 , Street) AS RowNumberFROM CustomersORDER BY Zip5 , StreetHowever the actual query that's running is ignoring my order by in my main dataset. This is messing up my Row Number. I did turn the sort options on in both the group and the tablix and it will sort correctly but it's leaving my RowNumber all messed up since it's not presorting.The main reason I was doing this is 2 reasons.1. So I could let users get a certain amount of data (like using a top 10)2. So that I can also use the row numbers in my headerText Box 1 (Right Aligned)= "Records " & MIN(ReportItems!RowNumber.Value) & " to "TextBox2 (Left Aligned)=MAX(ReportItems!RowNumber.Value) & " of " & Count(Fields!RowNumber.Value, "DataSet1") & " Total Records"If I could make the Main Order By Clause work before the dataset has to sort it then I'd be golden. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-05 : 16:15:51
|
what do you mean by its ignoring order by? your select should give you records in order of Zip5,Street. what else are you expecting to get as output?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-05 : 16:27:45
|
visakh16,Hopefully This makes senseMy Dataset 1 consists of SELECT *,ROW_NUMBER() OVER(ORDER BY Zip5 , Street) AS RowNumberFROM CustomersORDER BY Zip5 , Street** Note , I have all fields listed instead of Select * but due to the data I cannot post it on here. **However what the DataSet1 Appears to be doing is thisSELECT *FROM CustomersIf I run this query in Managment Studio and then go and look at my RowNumber Column it looks to just be doing a select * and giving the order that it's coming back (Without an OrderBy)I've read that this can be an issue sometimes and you will have to go to :Row Groups Group Properties Sortingand then set the sorting here. Which is fine. I can make the data sort that direction. But since it's happening after it's already ran the data, my ROW_NUMBER() OVER(ORDER BY Zip5 , Street) data is no longer in order.So instead of showing Address 1 RowNUmber 1Address 2 RowNumber 2 Address 3 RowNumber 3It's ShowingAddress 1 RowNumber 3Address 2 RowNumber 1Address 3 RowNumber 2So it is showing the main data in the correct order, but only after I either go into RowGroups or the tablix and set the sorting there. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-05 : 16:57:35
|
are there multiple records with same address? anyways this should give you result on order of row numberSELECT *FROM(SELECT *,ROW_NUMBER() OVER(ORDER BY Zip5 , Street) AS RowNumberFROM Customers)tORDER BY RowNumber ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-05 : 22:38:47
|
Visakh16,If I run the query in the query designer then I get data as follows which is correct...State Zip5 Street Address RowNumberWashington 99201 Main Street 123 1Washington 99201 Main Street 234 2Washington 99201 Main Street 345 3Washington 99201 New Rd 1 4State Zip5 Street Address RowNumberWashington 99201 Main Street 123 3Washington 99201 Main Street 234 2Washington 99201 Main Street 345 1Washington 99201 New Rd 1 4So it will list them correctly. But again only if I go into the tablix and put the sorting there. It seems to ignore my order by in the dataset itself. If I try to add the Row Number in the Tablix Sorting then it would be like thisState Zip5 Street Address RowNumberWashington 99201 Main Street 345 1Washington 99201 Main Street 123 2Washington 99201 New Rd 1 3Washington 99201 Main Street 234 4 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-05 : 22:44:40
|
you cant guarantee order of display inside tablix unless you put an explicit sorting in it------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-05 : 23:29:49
|
Visakh16, I'm not sure if this is the best way but it's working.IF OBJECT_ID('tempdb..#Customers') IS NOT NULL DROP TABLE #CustomersSELECT *INTO #CustomersFROM CustomersORDER BY Zip5 , StreetSELECT * , ROW_NUMBER() OVER(ORDER BY Zip5 , Street) AS RowNumberFROM #CustomersThis is keeping the correct order by since I put it in the temp table first. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-05 : 23:41:14
|
thats fine but unless you put an explicit sort on tablix you cant guarantee the order of retrieval.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|