Home  »  Code Snippets  »  SQL Server  »

Insert data into Table where not exists

 Posted By : Manoranjan SahooPosted Date : 19/01/2012 09:01:38 AM Category : SQL Server Points : 2

Sometimes we need to insert data into table where data is not existing in the table.  This can be done by using below query.

Code :

INSERT INTO <TableName>(<ColumnName>)             
           SELECT DISTINCT 'Value To Enter'           
           WHERE NOT EXISTS (SELECT * FROM <TableName> B WHERE B.<ColumnName>='Value To Enter')
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.