June 13, 2020 at 7:41 pm
Declare @Intstr1 varchar(100)
Declare @Intstr2 varchar(100)
Set @Intstr1 = '1,2,3,4,5,6,7,8,9' -- This will NOT contain duplicates
Set @Intstr2 = '4,6,6,7,7' -- This string may have duplicates but surely exists in str1
Need a t-sql for finding numbers from Str1 which are NOT in Str2
Please help.
Expected output..
@output = '1,2,3,5,8,9'
June 13, 2020 at 8:45 pm
Out of curiosity, what have you tried to solve this problem?
I ask because I already see one possible solution.
June 13, 2020 at 9:48 pm
I tried using loops which I know not a better way. Is there any solution with direct sql query to get required output.
June 14, 2020 at 12:24 am
SELECT STRING_AGG(d.value,',')
FROM (
SELECT value
FROM STRING_SPLIT(@Intstr1,',')
EXCEPT
SELECT value
FROM STRING_SPLIT(@Intstr2,',')
) d
;
--Jeff Moden
Change is inevitable... Change for the better is not.
June 14, 2020 at 1:43 am
Worked like a champ. Thanks jeff.
June 14, 2020 at 3:27 am
Worked like a champ. Thanks jeff.
Thanks for the feedback.
To be sure, though, do you understand how and why it works?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 17, 2020 at 7:51 pm
Wow. So simple now.
Still labouring in 2008, our next version is supposed to be 2016, with no set date for that.
I figure I'll be able to start using STRING_AGG sometime around 2028 - when we upgrade to 2019 :-\
June 17, 2020 at 8:03 pm
Wow. So simple now.
Still labouring in 2008, our next version is supposed to be 2016, with no set date for that.
I figure I'll be able to start using STRING_AGG sometime around 2028 - when we upgrade to 2019 :-\
Heh... been there, done that. Not fun.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy