sql server - How to update table when rows of one table are different from the other -


i have table table1 , temporary table temp2. temp2 contains updated values want update in table1. so, rows different want update values temp2 table 1. tried not working.

update role_master set role_desc=role_descc , role_version_number =role_version_number+1,role_dept=role_deptt,role_all_clients=role_all_clientss,             role_admin=role_adminn,role_super_admin=role_super_adminn,role_modified_date = getdate(),role_modified_by = 't6086'  #temp1 role_id in             (select #temp1.role_idd #temp1  left join role_master on (#temp1.role_descc = role_master.role_desc , #temp1.role_deptt=role_master.role_dept)             role_master.role_desc null , role_master.role_dept null) 

hard without knowing schema of 2 tables ... should possible join 2 tables , decide condition rows update ... check out simple example ... maybe helps

create table #temp1 (id int, val nvarchar(100)) create table #temp2 (id int, val nvarchar(100))  insert #temp1 (id, val) values (1, 'eins') insert #temp1 (id, val) values (2, 'eins') insert #temp1 (id, val) values (3, 'eins')  insert #temp2 (id, val) values (1, 'zwei') insert #temp2 (id, val) values (2, 'eins') insert #temp2 (id, val) values (3, 'eins')  update #temp1 set #temp1.val = b.val     #temp1 join #temp2 b on a.id = b.id     a.val <> b.val  select @@rowcount           -- returns 1 because 1 row updated select * #temp1 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -