Thursday, 12 September 2013

insert in same table avoid duplicate

insert in same table avoid duplicate

below is my sql statement
INSERT INTO tblRB_ReportFilterUserAssoc
(
[FK_ReportID]
,[UserID]
,[FilterExpression]
,[DateFilterValues]
,[IsCustomReport]
)
SELECT
[FK_ReportID]
,@UserId
,[FilterExpression]
,[DateFilterValues]
,[IsCustomReport]
FROM
tblRB_ReportFilterUserAssoc
WHERE
UserID = @AssignedUserID
there is condition of UserID
it is basically inserting all the records in same records of a particular
user for another user
i have to check if the particular filter is exist for new user then dont
insert
case
how can i do that
[FK_ReportID] user_id
1 100
2 100
3 100
1 101
now i want to insert all records of userid 100 to same table for userid
101, but as report id 1 is already there in table for 101 so it should
insert only records for 2,3,4
how should we restrict that
Thank You

No comments:

Post a Comment