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 |
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-10-08 : 06:27:52
|
| i have two tables PRODUCT, MOVIMENT MOVIMENT TABLE HAS a lot of record of the same produts I would like to update PRODUCT Table with the Latest record (mov_LastDate) for each Product in MOVIMENT TablePRODUTCT pro_code (key) pro_qty , pro_lastdade123 ?? ?? 567 ?? ?? ....MOVIMENT mov_code(key) Docto mov_qty , pro_lastdade123 1 12 12/10/04 123 13 67 09/09/04 123 12323 12 08/07/04 567 457 33 04/07/04 ....Upadate produtoset pro_lastqty = mov_qty pro_lastdate = mov_lastdatei am really lost heretksClages |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-08 : 06:42:29
|
will this do?Update t1set pro_lastqty = (select mov_qty from (select max(mov_qty) as mov_qty, pro_lastdate from MOVIMENT where t1.pro_code = mov_code group by pro_lastdate) t2), pro_lastdate = (select max(pro_lastdate) from MOVIMENT where t1.pro_code = mov_code)from produto t1 Go with the flow & have fun! Else fight the flow |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-10-08 : 11:15:22
|
| tks, but i dont want the MAX(qty) i want the Qty ,LastDate fromthe Lastdate recordif the LastDate Record has the qty = 678 i want this qty.TksClagesUpdate t1set pro_lastqty = (select mov_qty from (select max(mov_qty) as mov_qty, pro_lastdate from MOVIMENT where t1.pro_code = mov_code group by pro_lastdate) t2), pro_lastdate = (select max(pro_lastdate) from MOVIMENT where t1.pro_code = mov_code)from produto t1 |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-10-08 : 12:13:38
|
| tks, but i dont want the MAX(qty) i want the Qty ,LastDate fromthe Lastdate recordif the LastDate Record has the qty = 678 i want this qty.TksClagesUpdate t1set pro_lastqty = (select mov_qty from (select max(mov_qty) as mov_qty, pro_lastdate from MOVIMENT where t1.pro_code = mov_code group by pro_lastdate) t2), pro_lastdate = (select max(pro_lastdate) from MOVIMENT where t1.pro_code = mov_code)from produto t1 |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-10-08 : 12:13:56
|
| tks, but i dont want the MAX(qty) i want the Qty ,LastDate fromthe Lastdate recordif the LastDate Record has the qty = 678 i want this qty.TksClagesUpdate t1set pro_lastqty = (select mov_qty from (select max(mov_qty) as mov_qty, pro_lastdate from MOVIMENT where t1.pro_code = mov_code group by pro_lastdate) t2), pro_lastdate = (select max(pro_lastdate) from MOVIMENT where t1.pro_code = mov_code)from produto t1 |
 |
|
|
CLages
Posting Yak Master
116 Posts |
Posted - 2004-10-08 : 12:14:56
|
| this was the solution i did.tksClagesUpdate produto2 set pro2_vlultcompra = ( select top 1 mov_prunit from moviment where mov_dtlcto <= getdate() and mov_flag = 1 and mov_deposito = pro2_deposito and mov_codigo = pro2_codigo order by mov_dtlcto DESC ), pro2_dtultcompra = ( select top 1 mov_dtlcto from moviment where mov_dtlcto <= getdate() and mov_flag = 1 and mov_deposito = pro2_deposito and mov_codigo = pro2_codigo order by mov_dtlcto DESC )from moviment where mov_deposito = pro2_deposito and mov_deposito = '100' |
 |
|
|
|
|
|
|
|