Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call User-defined function in SELECT statement with Column Name as parameter?

Tags:

sql

sql-server

SQL Server 2005

I want to call UDF that returns table in SELECT statement as below.

select *, GetIptoCountry(IP_address) as country from tblInfo

but I am getting following error

'GetIptoCountry' is not a recognized built-in function name.

IP_address is the column in tblInfo.

How can I call UDF like this?

like image 250
Imad Avatar asked Jul 03 '26 20:07

Imad


1 Answers

You have to use the fully qualified name of the function including the schema name :

For example (if the scema is dbo), you can call the function with dbo.GetIptoCountry():

select *, dbo.GetIptoCountry(IP_address) as country from tblInfo

UPDATE:

According your last comment, you seems to have a table-valued function (wich returns table rows), not a scalar-valued function (wich returns a value), so the call can be done like this:

Select * from dbo.GetIptoCountry('your_ip_adress');

Your final query can looks like:

select * 
from tblInfo 
cross apply dbo.GetIptoCountry(IP_address)  tblCountry
like image 194
Kobi Avatar answered Jul 06 '26 11:07

Kobi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!