The following query does not fail but does not insert the unique values either.
I only want to insert unique values
DECLARE @user_id AS varchar(80)
DECLARE @real_name as varchar(250)
--New Unique values are "aaa" and they do not exist in the target table
SET @user_id = 'aaa'
SET @real_name = 'aaa'
INSERT INTO TargetTable
([user_id],real_name)
SELECT @user_id, @real_name
WHERE NOT EXISTS
(SELECT [user_id],real_name FROM TargetTable)
whereclause in the 2nd select?where not exists( select user_id,real_name from targetTable)" is checking if it finds anything in that table.. so you might wanna put awhereclause to check if the values you're trying to insert do not exist in that table..