SQL Server insert into non duplicates -


table objects:

create table objects(     id int identity primary key,     name varchar(50) unique ) 

lets have in table records a,b,c. inserting new rows given string example 'd,e,f,c,b,d', using function changing csv string table , returning it.

i need insert string example not in objects table, d,e,f. how can it? thinking about

insert objects(names) select distinct names split('d,e,f,c,b,d') except select names objects 

but sure has better sollution.

i used merge , works

merge objects using (select distinct name split(@string,',')) s on objects.name=s.name when not matched insert(name) values (split.name); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -