INSERT INTO TABLE IF NOT EXISTS recordin table Is Inserting Multiple times single record [Resolved]

Posted by KASANI007 under Sql Server on 5/27/2015 | Points: 10 | Views : 473 | Status : [Member] | Replies : 1
The below is the sql statement that inserts the record if only the record is not exists in table.. but the statement i written is inserting multiple times the same record... please help me to resolve my problem..

Hide Copy Code
INSERT INTO TableName(AccountNo,Customer,ContactNo) select 'AP1234','Saketh','984822338' FROM TableName WHERE NOT EXISTS(Select * From TableName Where AccountNo='AP1234');


Posted by: KASANI007 on: 5/27/2015 [Member] Starter | Points: 25


i found myself after some workouts..
I Have To add DISTINCT to select command

now it Inserting The Record Single Time Only,

INSERT INTO TableName(AccountNo,Customer,ContactNo) select DISTINCT 'AP1234','Saketh','984822338' FROM TableName WHERE NOT EXISTS(Select DISTINCT AccountNo From TableName Where AccountNo='AP1234');

KASANI007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response