开发者

Apply scalar function to each row

开发者 https://www.devze.com 2023-03-25 01:40 出处:网络
I have a function that works l开发者_C百科ike this: select score from comparestrings(@String1,@string2)

I have a function that works l开发者_C百科ike this: select score from comparestrings(@String1,@string2)

I need to compare every row in a table(@string2) to @string1. Is it possible without While loop and a cursor? My function came from simmetrics library

The code of function is below:

ALTER FUNCTION 
[dbo].[BlockDistance](@firstword [nvarchar](255), @secondword [nvarchar](255))
RETURNS [float] WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [TextFunctions].[StringMetrics].[BlockDistance]


Is comparestrings a UDF that returns a table?

Instead, just make it return a scalar value and do this:

select comparestrings(@string1, tablestring) from yourtable


Don't call it row by row.

Store it row by row with a computed column if the inputs are constants or columns from the same row.

ALTER TABLE Mytable ADD
    Score AS comparestrings(Col1,Col2)

Then you can PERSIST it and index it too

0

精彩评论

暂无评论...
验证码 换一张
取 消