views:

28

answers:

0

Error message:

Warning : SQM1014: Unable to extract function 'dbo.ProductFamilyIndex_EN' from SqlServer. Null or empty full-text predicate.

function defined as:

CREATE FUNCTION [dbo].[ProductFamilyIndex_EN]
(   
    @topn int,
    @keywords nvarchar(4000)
)
RETURNS TABLE 
AS
RETURN 
(
    select top (@topn) ProductFamilyID 
    from (

        select pf.ProductFamilyID, t.[RANK] as _rank
        from containstable(ProductFamily, (Name_EN), @keywords, LANGUAGE 'English', @topn) t
        inner join ProductFamily pf on(pf.ProductFamilyID=t.[KEY])

        union all

        select p.ProductID as ProductFamilyID, t.[RANK] as _rank
        from containstable(Product, (LongDescription_EN, ShortDescription_EN), @keywords, LANGUAGE 'English', @topn) t
        inner join Product p on(p.ProductID=t.[KEY] and p.ProductFamilyID is null and p.Deleted is null)

    ) t
    group by ProductFamilyID
    order by max(_rank) desc
)

don't get confused by the union inside - that just means that a product without a family is a family on its own.

tried to give default values to the parameters:

@topn int = 1000,
@keywords nvarchar(4000) = 'test'

with the same result.

Using .NET 3.5 and sql2008.

EDIT: Problem solved. Apparently sqlmetal runs the function to figure out the return type, but insists on supplying null parameter instead of default, which seems like sqlmetal's bug. Way to work around it is to declare return type explicitly:

alter function [dbo].[ProductFamilyIndex_EN] (@topn int, @keywords nvarchar(4000))
returns @t table (ProductFamilyID int not null)
as begin
...
return end