Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 dont want to insert record if that exist

Author  Topic 

kkiranvr
Yak Posting Veteran

54 Posts

Posted - 2009-05-05 : 18:56:20
i need to insert record into a table if that record is not existing in the table.

Ex: Table name is "Testing" and having the column as Col1 and it is holding values as shown below.
Col1
8
9
10
v51



Now i am having a flat file and values are
8 Value is repeating(So i dont want to insert it)
11
10 Value is repeating(So i dont want to insert it)
15
16

i want to insert records into the table "Testing" as

Col1
8
9
10
v51
11
15
16

Thanks

-Thanks N Regards,
Chinna.

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-05 : 19:12:08
bcp the file to a staging table. Insert from there using "where not exists"..

insert into testing
select * from tab_stg where not exists (select * from testing where col1=tab_stg.col1)
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-05 : 22:43:56
insert into testing
select * from flat f left join testing t on t.col1 = f.col1
where t.col1 is null
Go to Top of Page
   

- Advertisement -