SQL Server Returns the intersection of two strings
Source: Internet
Author: User
Use JavaScript Arrays for calculation, Code As follows:
Copy code The Code is as follows: Use tempdb
Go
If (object_id ('fn _ getarray') is not null)
Drop function DBO. fn_getarray
Go
Create Function fn_getarray (@ every 1 varchar (8000), @ every 2 varchar (8000 ))
Returns varchar (8000)
As
Begin
Declare @ STR varchar (8000)
Set @ STR ='
VaR A = [''' + Replace (@ override 1, ',', ''', ''') + '''];
VaR B = [''' + Replace (@ override 2, ',', ''', ''') + '''];
VaR c = ""
For (VAR I = 0; I <A. length; I ++)
{
For (var j = 0; j <B. length; j ++)
{If (a [I] = B [J] & C. indexof (A [I]) <0)
C + = A [I] + ","
}
}
'
Declare @ object int
Declare @ r varchar (800)
Exec sp_oacreate 'msscriptcontrol. scriptcontrol', @ object output
Exec sp_oasetproperty @ object, 'language ', 'javascript'
Exec sp_oamethod @ object, 'eval', @ r out, @ Str
Return @ r
End
Go
Select DBO. fn_getarray ('abc, dced, f23e, gew432', '23c, ABC, f23e, geafd, ged ')
/* Output
ABC, f23e,
*/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service