comparing two string

  • Any suggestion on below:

    I need to compare two strings which have comma separated ISO Country codes.

    For example : String1 = '356,840'

    String2 = '840,356'

    Actually both string give same countries but if we do SQL compare they are not same.

    Is there anyway or any inbuilt SQL function which fits here.

    Note : I don't want to use table variable/Temp table due to some xyz constraints.

  • mailtoashokberwal (11/27/2013)


    Any suggestion on below:

    I need to compare two strings which have comma separated ISO Country codes.

    For example : String1 = '356,840'

    String2 = '840,356'

    Actually both string give same countries but if we do SQL compare they are not same.

    Is there anyway or any inbuilt SQL function which fits here.

    Note : I don't want to use table variable/Temp table due to some xyz constraints.

    you could do it with the DelimitedSplit8K function for example

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    DECLARE @String1 varchar(30) = '356,840',

    @String2 varchar(30) = '840,356'

    IF NOT EXISTS(

    SELECT fn.Item from dbo.DelimitedSplit8K(@String1,',') fn

    EXCEPT

    SELECT fn.Item from dbo.DelimitedSplit8K(@String2,',') fn

    )

    PRINT 'No Differences found'

    ELSE

    PRINT 'they are not the same, regardless of order'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply