user194076 user194076 - 7 months ago 36
SQL Question

Apply scalar function to each row

I have a function that works like 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]

Answer

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