I have two strings, I want to get difference between contents of two strings in SQL ??
for example,
Declare @String1 as varchar(100)='a,b,c,d,e';
Declare @String2 as varchar(100)='b,e';
Now i want difference between two strings as "a,c,d"
I have two strings, I want to get difference between contents of two strings in SQL ??
for example,
Declare @String1 as varchar(100)='a,b,c,d,e';
Declare @String2 as varchar(100)='b,e';
Now i want difference between two strings as "a,c,d"
Both strings must be split into their parts. In SQL-Server 2008 this is best to be done with an XML approach.
attention: If your data might include forbidden characters like
<>öä@€&
and not just plain latin characters like in your example, you'd need some extra effort...The rest is fairly easy: Just take all parts of
@String1
which are not found in@String2
.The concatenated result is - again - best to be done via XML
Try this:
First take the function from the following link Parse comma-separated string to make IN List of strings in the Where clause
Then use the following query;
Which will give you the following results;
Interesting task, Is it business requirement or what else?
Simple Way
Result