使用javascript的數(shù)組來計算,代碼如下:
復(fù)制代碼 代碼如下:
use tempdb
go
if (object_id ('fn_getArray' ) is not null )
drop function dbo . fn_getArray
go
create function fn_getArray (@ inStr1 varchar (8000 ), @ inStr2 varchar (8000 ))
returns varchar (8000 )
as
begin
declare @ str varchar (8000 )
set @ str = '
var a = [''' + replace (@ inStr1 , ',' , ''',''' )+ '''];
var b = [''' + replace (@ inStr2 , ',' , ''',''' )+ '''];
var c=""
for (var i=0;ia.length;i++)
{
for (var j=0;jb.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' )
/* 輸出
abc,f23e,
*/
您可能感興趣的文章:- sql server 交集,差集的用法詳解
- SQL語句的并集UNION 交集JOIN(內(nèi)連接,外連接)等介紹
- MySQL實現(xiàn)差集(Minus)和交集(Intersect)測試報告
- MySQL 查詢結(jié)果取交集的實現(xiàn)方法
- mysql-joins具體用法說明