Guys i have to do a insert in to a table when there is no record found. is it possible to do it with only sql query. i tried with case and if .
2 Answers
Just add the condition of your 'IF' to the WHERE of the INSERT for example
INSERT INTO People
(FirstName,LastName,Email)
SELECT @FirstName,@LastName,@Email WHERE @Email NOT IN (SELECT Email FROM People)
If the email address already exists in the table then the SELECT will return no rows and hence no insert will take place