SQL Server 2012 : insert data into table while checking for duplicates -


i have written query insert data sql server table excel, , need add check , see if information in table. when add where clause check table see if data i'm insert new, not add data, if new.

here code:

create table #master  (     brnbr varchar(10),     branchname varchar(100),     region varchar(100),     marketplace varchar(100),     enumber varchar(120),     fname varchar(100),     lname varchar(100),     sbslfname varchar(100),     sbl varchar(100),     title varchar(100),     status varchar(100),     startdate int );  insert #master (brnbr, branchname, region, marketplace, enumber, fname, lname, sbslfname, sbl, title, status, startdate) values ('tt000', 'test1', 'test2', 'test3', 't77777', 'test4', 'test5', 'test6', 'test7', 'sbs', 'a', '42005');  insert dbo.tbsbstest   select distinct      brnbr,      branchname,      region,      marketplace,      enumber,      fname,      lname,      sbslfname,      sbl,      title,      status,      convert(int, startdate, 102) startdate,      null termdate         #master         enumber not in (select distinct enumber dbo.tbsbstest);  drop table #master  select * dbo.tbsbstest branchname = 'test1'; 

pardon formatting - it's being written excel. unique identifier enumber. if comment out where clause update, not where clause in use.

any suggestions appreciated.

try using exists, condition, instead:

select distinct m.brnbr, m.branchname, m.region... #master m not exists(select t.enumber database.dbo.tbsbstest t t.enumber = m.enumber) 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -