sql - TSQL: Prevent Nulls update over existing data -


i have 2 tables:

  1. orders (table update , want keep existing data, , prevent overwriting nulls)

  2. wrk_table (this table identical orders can not guarantee columns have data when running update)

pk column 'master_ordernum' there many columns in tables, wrk_table have pk, data in other columns can not counted on.

i want wrk_table update orders actual data , not nulls. thinking along line:

update [orders]  set [status] = case when s.[status] not null s.[status] end  [wrk_table] s [orders].[master_ordernum] = s.[master_ordernum] 

the existing data in orders being updated nulls

does help?

update orders set name = work.name  orders  inner join work on orders.id = work.id , work.name not null 

not same col / table name should idea

edit

your sql, not tested

update orders set [status] = wrk_table.[status] [orders]  inner join wrk_table  on [orders].[master_ordernum] = [wrk_table].[master_ordernum] , wrk_table.[status] not null 

if want test , undo data (assuming don't have 100s of rows)

begin tran 

/* .. sql updates ... */

select * orders // review data  rollback tran // undo changes 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -