Error calling a T-SQL function

1

I have created a function with Transact-SQL that after the ISBN of a book returns 1 (if it exists) or 0 (if it does not exist), but calling the function gives me an error. The code:

CREATE FUNCTION fn_llibre_ok (@isbn varchar(13)) returns bit AS
begin

    declare @existeix bit

    if exists (select lib_isbn from llibre where lib_isbn = @isbn)
    begin       
        set @existeix = 1
    end
    else
    begin
        set @existeix = 0
    end

    return @existeix

end

I call the function with an ISBN that exists in the database:

select fn_llibre_ok('978-84-938011')

And I get this error

Msg 195, Level 15, State 10, Line 1
'fn_llibre_ok' no es un nombre de función reconocido.

I do not know if the function is wrong or that I do not call it well. If someone can give me a hand I would appreciate it

    
asked by gmarsi 12.06.2017 в 11:53
source

2 answers

2

I think you're missing the dbo in front of the show.

test select dbo.fn_llibre_ok ('went')

I hope this is a greeting

    
answered by 12.06.2017 / 12:47
source
1

To invoke the function, it is necessary to put in front of it the scheme to which it belongs. The default scheme is

dbo

Therefore invoke it as

dbo.fn_llibre_ok('iban')

It would be the right thing to do in most cases.

    
answered by 06.10.2017 в 12:48