Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ayu
Starting Member
43 Posts |
Posted - 2008-07-31 : 09:45:54
|
| i want like if same purchase order is 3 times in table then whatever is current one that i want..i want to retrive the max record from so what will be the query ? this what i havebut its not workingSELECT MAx(Orders.[Customer Name]) AS [LastOfCustomer Name], MAx(Orders.ScanDate) AS LastOfScanDate, max(Orders.SONumber) AS LastOfSONumber, Orders.PurchaseOrderNumber, max(Orders.CustomerComment) AS LastOfCustomerComment, max(Orders.ScanTime) AS LastOfScanTime, max(Orders.[Axapta Customer No]) AS AccountNoFROM OrdersGROUP BY Orders.PurchaseOrderNumber |
|
|
VGuyz
Posting Yak Master
121 Posts |
Posted - 2008-07-31 : 09:47:47
|
| Can u tell u'r issue with some sample data'sit would be easier to understand. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-31 : 09:48:49
|
[code]select *from ( select *, row_no = row_number() over (partition by PurchaseOrderNumber order by ScanDate desc) from Orders) awhere a.row_no = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2008-07-31 : 09:49:34
|
| Assuming that SONumber is what you want the max of then you'd have to select the max sonumber and group by order number, then join back. Something like this:select Orders.CustomerName,Orders.ScanDate,base.SoNumber,base.OrderNumberfrom Orders Oinner join(select max(SoNumber) as SoNumber,OrderNumberFROM Orders O Group by OrderNumber)baseon o.SoNumber=base.soNumberMike"oh, that monkey is going to pay" |
 |
|
|
|
|
|
|
|