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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Update Query

Author  Topic 

rpr
Starting Member

3 Posts

Posted - 2005-01-06 : 08:09:43
Hello,

Can i write a query to update fields in a row using values from two diferents tables? (How can i use the inner join?, etc)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 08:21:00
something like:

update t1
set col1 = t2.col1,
col2 = t2.col2
from MyTable1 t1 inner join MyTable t2 on t1.id = t2.id


Go with the flow & have fun! Else fight the flow
Go to Top of Page

rpr
Starting Member

3 Posts

Posted - 2005-01-06 : 08:59:38
Hi again,
I really dont get it, why did you put From MyTable1 t1 ?, whats MyTable?, look what i wrote in the query analizer:

UPDATE [@Ventas_Enero_04]
SET [@Ventas_Enero_04].Vtas_Cajas_est = [@Ventas_Enero_04].Vtas_Cajas * [@Conversion_cajas].CS_CF
From mytable [@Conversion_cajas] inner Join mytable [@Ventas_Enero_04]
On [@Ventas_Enero_04].Cod_articulo_sigma = [@Conversion_cajas].Articulo
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 09:05:05
well as i have no idea how your tables are named MyTable1 and MyTable are Table Names
that you need to change to your table names.
i'm guessing you're using table variables in your query, right?
will this do?
UPDATE t2
SET Vtas_Cajas_est = t2.Vtas_Cajas * t1.CS_CF
From [@Conversion_cajas] t1 inner Join [@Ventas_Enero_04] t2
On t1.Cod_articulo_sigma = t2.Articulo


Go with the flow & have fun! Else fight the flow
Go to Top of Page

rpr
Starting Member

3 Posts

Posted - 2005-01-06 : 09:24:04
Thanks a lot! i finnaly got it!
Go to Top of Page
   

- Advertisement -