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 |
|
Saeed
Starting Member
39 Posts |
Posted - 2003-05-29 : 22:43:46
|
| Just trying to group by mccn & WarehouseN from #ValidRoll and find the max(dateReceved) and update it in #Report...update #Report set #Report.LastReceipt = ( select max(a.DateReceived) from #ValidRoll a,#Report b where a.mccn=b.mccn and a.WarehouseN=b.WarehouseN) where #Report.mccn =#ValidRoll.mccn and #Report.WarehouseN=#ValidRoll.WarehouseNBut SQL does not like this |
|
|
Saeed
Starting Member
39 Posts |
Posted - 2003-05-29 : 23:12:06
|
| This seems to be a clearer solution however without the fun() max , it works but with it , it does notupdate #Report set #Report.LastReceipt = max(#ValidRoll.DateReceived) where a.mccn =b.mccn and a.WarehouseN =b.WarehouseN |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-05-30 : 07:55:14
|
| Hi Saeed:Try this - UPDATE #Report SET #Report.LastReceipt = X.DateRecFROM #Report INNER JOIN(SELECT a.mccn, a.WarehouseN, MAX(a.DateReceived) AS DateRec from #ValidRoll a INNER JOIN #Report b ON a.mccn=b.mccn and a.WarehouseN=b.WarehouseNGROUP BY a.mccn, a.WarehouseN) XON #Report.mccn = X.mccn and #Report.WarehouseN=X.WarehouseNHTHOwais |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-05-30 : 08:09:32
|
| -- This select gives the Max Date Received for all mccnSELECT A.mccn, MAX(A.DateReceived) as MaxDateReceivedFROM #ValidRoll AJOIN #Report B ON A.mccn = B.mccn AND A.WarehouseN = B.WarehouseNGROUP BY A.mccn-- Now for the updateUPDATE #ReportSET LastReceipt = MaxDateReceivedFROM #ReportINNER JOIN (-- Insert the first query above here ) B ON B.mccn = #Report.mccnHTH,Sam* Owais' query is correct.. SamEdited by - SamC on 05/30/2003 08:11:07 |
 |
|
|
joseph
Starting Member
10 Posts |
Posted - 2003-06-22 : 14:57:55
|
| try:update #Report set LastReceipt =(select max(DateReceived) from #ValidRoll where #Report.mccn =mccn and #Report.WarehouseN=WarehouseN )It must work |
 |
|
|
Saeed
Starting Member
39 Posts |
Posted - 2003-06-22 : 19:24:00
|
| thanks to all that responded |
 |
|
|
|
|
|