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 with data from another table

Author  Topic 

Ats
Starting Member

32 Posts

Posted - 2009-04-05 : 07:47:37
Hi i am trying to update data in one of my tables with new data i have recieved, Firstly I have a table called compliance it has about 10 columns I need to update data in just 2 of the columns, also it takes 2 fields to get the unique identifier. the structure of the compliance table is

Permitid
year
verified
Allocation
surrendered
cer
eru

This is the original table structure with the permit id and year fields being used as the unique identifier.

The structure of the table which has the new data is as follows and is called newdata

Permitid
year
verified
Allocation

So I want to update the verified and allocation in the compliance table withe the data in the new data table. I also want to state if the data in the new data table is = 0 then dont update. I have been trying to do this but it is not working very well, I keep seeing different versions on the net and im not sure of which one to use.

any help would be appreciated

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-05 : 16:29:10
Can you try this..

update a
set a.verified = case when b.verified <> 0 then b.verified end,
a.Allocation = case when b.Allocation <> 0 then b.Allocation end
from compliance a inner join newdata b
on a.Permitid = b.Permitid and a.year = b.year

Go to Top of Page
   

- Advertisement -