How to use SQL function inside my SQL query

Suppose I have an SQL function called MAGIC that returns the magic value of a number.

Suppose I want to write an SQL query that returns a list of numbers from an SQL table along with their magic values.

My instinct is to write

 SELECT number, MAGIC(number) FROM NUMBERS; 

However, this returns the error message "MAGIC is not a recognized function name. How can I make this work?

EDIT: It looks like MAGIC is set up for a table function, even if it returns only one value. My database administrator will not give me access to the entire functional code of the database, so I have to work with it this way.

+4
source share
3 answers

If it is a scalar value function, fully qualify your function in TSQL:

 SELECT number, dbo.MAGIC(number) FROM NUMBERS; 
+5
source

If it is a table function, just do this:

 SELECT n.number, mn.number FROM numbers as n CROSS JOIN dbo.Magic(n.number) as mn 
0
source

Try using the function as a field ... this is for TSQL.

 SELECT number, -- start function (SELECT function_field_name FROM dbo.MAGIC(number)) AS magic_number -- end function FROM dbo.NUMBERS 
0
source

All Articles