Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Update

Status
Not open for further replies.

jrprogr

Programmer
Jul 20, 2006
74
US
Please help..
I am writing a update query which has to update the @prod2 table column prod1 with the values of @Upprod table column prod2.
Please correct the query if anything needs to be corrected in the below query.
there are nearly 1500 records to be updated below is sample data..

declare @Prod2 table
(

Csid bigint,
Prod1 numeric(5)
)
insert into @Prod2
select 4103, 1946 union all
select 4101, 1956 union all
select 4102, 1904

select * from @prod2 order by csid

declare @Upprod table
(
Csid int,
Prod2 numeric(5)
)

insert into @Upprod
select 4102, 1956 union all
select 4103, 1936 union all
select 4101, 1964

select * from @Upprod order by csid

update @prod2 set prod1=Prod2 from @prod2 A,@Upprod B
Where A.csid=B.csid

select * from @prod2 order by csid
 
Change:

update @prod2 set prod1=Prod2 from @prod2 A,@Upprod B
Where A.csid=B.csid

To:

Code:
update A 
set    A.prod1= B.Prod2 
from   @prod2 A
       Inner Join @Upprod B
         On A.csid=B.csid

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top