Print the return value of user-defined function

990 views Asked by At

I simply want to do this something like this for testing the function:

PRINT fnctGeneric([argument])

I've searched around but can't find anything. Tried https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=SQL+Print+function+return+value -- https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=SQL+Print+return+value+from+user-defined+function -- https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=SQL+Print+return+value+from+function

and searched on stack

https://stackoverflow.com/search?q=Print+return+value+of+function+SQL

but haven't found anything.

I'd have thought this would be easy, so easy to find, but it's not, so I can only assume I'm missing something.

So my question is how do you simply print the return value of a function? Do I need to store the value, in a variable say, before printing it?

Can't Do this:

DECLARE @Return AS VARCHAR(MAX)
SET @Return = fnctCalculateCertName(4471)
PRINT @Return

Because of this

Msg 195, Level 15, State 10, Line 205 'fnctCalculateCertName' is not a recognized built-in function name.

Can't do my first attempt:

PRINT fnctCalculateCertName(4471)

again because of the same error. Can't do this:

SELECT fnctCalculateCertName(4471) FROM system

Or this:

DECLARE @Return AS VARCHAR(MAX)
SELECT @Return = fnctCalculateCertName(4471) FROM system
PRINT @Return

I can't believe it's so difficult to print the results of a function like this :/

And it's definitely in my database, I can see it in the Scalar-valued Functions tab

1

There are 1 answers

7
Joao Leal On BEST ANSWER

You need to add the schema, when calling functions:

PRINT dbo.fnctGeneric([argument])