I have a function that will get two lists of IDs and I want to get back the count of differences. If both lists are equal, then 0, otherwise the count.
This I will call:
SELECT [dbo].[Redline_compareBaseProjSuccessors]
( '2498,2502,2510,2521,2841',
'2498,2502,2510,2521,2532,2820,2841') as isDifferent
My function was:
ALTER FUNCTION [dbo].[Redline_compareBaseProjSuccessors] (@projSuccessors varchar,@baseSuccessors varchar)
RETURNS int
AS
BEGIN
DECLARE @proj_assignment_ids TABLE (obj_id int)
DECLARE @base_assignment_ids TABLE (obj_id int)
DECLARE @is_different int
INSERT INTO @base_assignment_ids
SELECT base_assignment_id as obj_id
FROM base_assignment
WHERE base_assignment_id IN (@baseSuccessors)
INSERT INTO @proj_assignment_ids
SELECT base_assignment_id AS obj_id
FROM proj_assignment
WHERE proj_assignment_id IN (@projSuccessors)
SELECT @is_different = Count(obj_id)
FROM @base_assignment_ids
WHERE obj_id NOT IN (SELECT obj_id FROM @proj_assignment_ids)
RETURN @is_different
END
The value of @base_assignment_ids
was : 2498,2502,2510,2521,2841,2532,2820
and the value of @proj_assignment_ids
= 2498,2502,2510,2521,2841
so I would expect 2 as return value, but I get 0
What was wrong?