Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort formula 2

Status
Not open for further replies.

tonyvee1973

IS-IT--Management
Oct 22, 2009
156
GB
Hiya
I need to sort some data and have built a query but need to get it right as this wont work. Can someone see where i am going wrong?
Think the issue is where i have put the "where POD_QTYRESERVED>0" is the wrong place as if i delete it the query works ok.
Thanks as always

Select POP_DETAIL.POD_STOCK_CODE,
POP_DETAIL.POD_QTYRESERVED,
POP_DETAIL.POD_REQDATE,
Row_Number() Over (Partition By POD_STOCK_CODE Order By POD_REQDATE DESC) As RowId where POD_QTYRESERVED>0
From POP_DETAIL
 
In fact... I would probably skip the Row_Number() part and just use this Order By clause...

Code:
Select POD_STOCK_CODE,
       POD_QTYRESERVED,
       POD_REQDATE
From   @test 
[!]Order By POD_STOCK_CODE, 
         Case When POD_QTYRESERVED > 0 Then 0 Else 1 End, 
         POD_REQDATE[/!]




-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Ok, had to make an adjustment in my script to allow for this but now it works as it should. :)
Thanks Borislav for all your help and patience, really appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top