select pnrid >>>> ,[SEGMENTTATTOONUMBERS] >>>> ,[PAXTATTOONUMBERS] >>>>from tst >>>>where not exists (select pnrid >>>> ,associatedsegmenttattoonumbers >>>> ,associatedpaxtattoonumbers >>>> from ticket > >>>> where pnrid = tst.pnrid >>>> and associatedsegmenttattoonumbers = segmenttattoonumbers >>>> and associatedpaxtattoonumbers = paxtattoonumbers) >>>> order by pnrid>>>>
>>CREATE FUNCTION [dbo].[fnSplitString] >>( >> @string NVARCHAR(MAX), >> @delimiter CHAR(1) >>) >>RETURNS @output TABLE(splitdata NVARCHAR(MAX) >>) >>BEGIN >> DECLARE @start INT, @end INT >> SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) >> WHILE @start < LEN(@string) + 1 BEGIN >> IF @end = 0 >> SET @end = LEN(@string) + 1 >> >> INSERT INTO @output (splitdata) >> VALUES(SUBSTRING(@string, @start, @end - @start)) >> SET @start = @end + 1 >> SET @end = CHARINDEX(@delimiter, @string, @start) >> >> END >> RETURN >>END >>>>
>.... >EXISTS( >select pnrid > ,associatedsegmenttattoonumbers > ,associatedpaxtattoonumbers >from ticket >where pnrid = tst.pnrid > and associatedsegmenttattoonumbers = segmenttattoonumbers > and associatedpaxtattoonumbers IN (SELECT Splitdata > FROM dbo.fnSplitString(paxtattoonumbers, ',') Test) >) >Thanks, I am also trying a CROSS APPLY to see which will give better performance.