[英]How to call User-defined function in SELECT statement with Column Name as parameter?
SQL Server 2005 SQL Server 2005
I want to call UDF that returns table
in SELECT statement as below.我想调用在 SELECT 语句中返回
table
UDF,如下所示。
select *, GetIptoCountry(IP_address) as country from tblInfo
but I am getting following error但我收到以下错误
'GetIptoCountry' is not a recognized built-in function name.
'GetIptoCountry' 不是可识别的内置函数名称。
IP_address
is the column in tblInfo
. IP_address
是tblInfo
的列。
How can I call UDF like this?我怎么能像这样调用UDF?
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()
:例如(如果 scema 是
dbo
),您可以使用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
My problem was much more simple.我的问题要简单得多。 I had reconnected to the database.
我已经重新连接到数据库。 SSMS still had me as using the Master Database.
SSMS 仍然让我使用主数据库。
I just click the drop down or run a "USE MyDatabase" statement and voila.我只需单击下拉菜单或运行“USE MyDatabase”语句,瞧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.