Advertisement
lukifrancuz

BD3_K2_Z3_g1

Jan 19th, 2023
1,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.99 KB | None | 0 0
  1. merge Production.Suppliers as target
  2. using (
  3.     select
  4.        MY_XML.Company.query('companyname').value('.', 'nvarchar(40)') as companyname,
  5.        MY_XML.Company.query('contacttitle').value('.', 'nvarchar(40)') as contacttitle,
  6.        MY_XML.Company.query('contactname').value('.', 'nvarchar(40)') as contactname,
  7.        MY_XML.Company.query('postalcode').value('.', 'nvarchar(40)') as postalcode
  8.     from (select cast(MY_XML as xml)
  9.           from openrowset(bulk 'C:\Users\----\Suppliers.xml', single_blob) --tu sciezka nowa!!!!
  10.           as T(MY_XML)) AS T(MY_XML)
  11.           cross apply MY_XML.nodes('Suppliers/Company') as MY_XML (Company)
  12. ) as source
  13. on target.companyname = source.companyname
  14. when matched then update set contacttitle = source.contacttitle, contactname = source.contactname, postalcode = source.postalcode
  15. when not matched then insert(companyname, contacttitle, contactname, postalcode) values(source.companyname, source.contacttitle, source.contactname, source.postalcode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement