November 27, 2013 at 6:18 am
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.
November 27, 2013 at 6:37 am
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
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply