Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Non-Normalised Table and Joins
Message
From
24/11/2016 12:33:13
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Miscellaneous
Thread ID:
01643905
Message ID:
01643913
Views:
24
>>>>
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
>>>>
>>>>How would I adjust this to handle the splitting up of the PaxTattooNumbers?
>>>
>>>If you use SQL Server 2016 :-) there is biult-in function STRING_SPLIT.
>>>For smaller version google TSQL SPLIT :-)
>>
>>I am on SQL 2012 so can't use the suggested built in function. From what I am seeing, I need to write (or copy one that was written already) a tsql function which will split it up.
>>
>>I'm not seeing how I would then apply that to my problem, can you help fill in the blank for me?
>>
>>Say I have a function:
>>
>>
>>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
>>
>>
>>How would I adjust my query to get this to work?
>
>
>
>Something like:
>
>....
>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.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform