标量值函数 - 输出表

时间:2016-01-06 15:25:56

标签: sql sql-server mds

我最近在SQL Developer实例上安装了Master Data Services,现在我可以在SQL Studio Manager中选择MDS数据库时运行以下查询:

SELECT mdq.Similarity(N'Alexia Geogio', N'Alexandra George', 0, 0.0, 0.0);

现在,请参阅下面的DDL:

create table #Person (ID int not null identity, Name varchar(100), primary key (ID))
INSERT INTO #Person (Name) values ('Alexia Geogio')
INSERT INTO #Person (Name) values ('Alexandra George')
INSERT INTO #Person (Name) values ('Ian')
INSERT INTO #Person (Name) values ('Iain')

是否可以使用SQL语句(三列)获得这样的输出:

Alexia Geogio Alexandra George 0.5625
Alexandra George Alexia Geogio 0.5625
Ian Iain 0.75
Iain Ian 0.75

mdq.Similarity是任何不知道的人的标量值函数。

我相信因为它不是一个表值函数,所以我无能为力。

1 个答案:

答案 0 :(得分:2)

我认为像这样的查询可以满足您的需求:

select name1, name2, similarity
from (select p1.name as name1, p2.name as name2,
             mdq.Similarity(p1.name, p2.name, 0, 0.0, 0.0) as similarity
      from #person p1 cross join
           #person p2
     ) pp
where similarity > @SimilarityLimit  -- perhaps 0
order by similarity;