Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

comparing two string Expand / Collapse
Author
Message
Posted Wednesday, November 27, 2013 6:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 18, 2013 5:36 AM
Points: 7, Visits: 38
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.

Post #1518039
Posted Wednesday, November 27, 2013 6:37 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:22 PM
Points: 12,890, Visits: 31,849
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1518049
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse