DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   UPDATE with INNER JOIN (http://www.daniweb.com/forums/thread148086.html)

rdneira Sep 28th, 2008 9:40 pm
UPDATE with INNER JOIN
 
I have the next query, but it doesn't update when I have but of a product with the same code in the table detallefacturas

UPDATE dbo.Kardex SET dbo.Kardex.SaldoDocumental = dbo.Kardex.SaldoDocumental + dbo.DetalleFacturas.Cantidad
FROM dbo.Kardex INNER JOIN dbo.DetalleFacturas ON
(dbo.Kardex.CodigoZofriID = dbo.DetalleFacturas.CodigoZofriID) WHERE dbo.DetalleFacturas.FacturaID = @FacturaID

for example.
DetalleFacturas
Item CodigoZofriID Cantidad
1 001-08-000124-001 10
2 001-08-000124-001 20
3 001-08-000222-001 5

Kardex
CodigoZofriID IngresoDocumental SaldoDocumental
001-08-000124-001 400 370
001-08-000222-001 100 95

once made the query this is what see

Kardex
CodigoZofriID IngresoDocumental SaldoDocumental
001-08-000124-001 400 380 BAD
001-08-000222-001 100 100 OK

thanks. Rodrigo.

AndrewM001 Oct 27th, 2009 5:01 am
Have you tried:
UPDATE dbo.Kardex
  SET dbo.Kardex.SaldoDocumental = dbo.Kardex.SaldoDocumental + dbo.DetalleFacturas.Cantidad
FROM dbo.DetalleFacturas
WHERE dbo.DetalleFacturas.FacturaID = @FacturaID
  AND dbo.Kardex.CodigoZofriID = dbo.DetalleFacturas.CodigoZofriID


All times are GMT -4. The time now is 2:20 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC