sql server - update existing column values and insert new in record doesn't exist in SQL when importing from CSV -


can please me on following?

we have payroll software runs on sql server. have update payroll category sql server can reflect on software.

this excel file:

employee number  payroll category  rate ------------------------------------------ 111111           011               32.21 111111           012               56.23 111111           013               12.52 111111           021               45.21 111112           011               36.21 111112           012               56.23 111112           013               42.54 111112           021               85.21 

these current values in database table masterpaycard

 employee number     payroll category  rate  -------------------------------------------     111111           011               0.00     111111           012               0.00     111111           013               10.25      111112           011               36.21     111112           012               12.50     111112           013               41.25     111112           021               85.21 

so if see following record not present in database, present in .csv, have insert it.

 111111           021               45.21 

here employee number , payroll category fks employee , payroll category tables.

so final results should in database , in front end this.

employee number    payroll category    rate --------------------------------------------     111111           011               32.21     111111           012               56.23     111111           013               12.52     111111           021               45.21     111112           011               36.21     111112           012               56.23     111112           013               42.54     111112           021               85.21 

i guess in simple words if payroll category match in masterpaycard table update category value .csv, , if can not find payrollcategory insert new category employee , add value csv.

please help.

this type of approach need take...

create table #table1 (     id int,     value varchar(10) )  create table #table2 (     id int,     value varchar(10) )  insert #table1 values (1, 'aaa') insert #table1 values (2, 'bbb')  insert #table2 values (1, 'zzz') insert #table2 values (3, 'ccc')  select * #table1 select * #table2  --insert data table2 table1 if doesn't exist in table1 insert #table1  select #table2.* #table2 left join #table1 on #table2.id = #table1.id #table1.id null  --update data in table1 table2 if exist in table1 update #table1 set value = #table2.value #table2 left join #table1 on #table2.id = #table1.id #table1.id not null  select * #table1 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -