简体   繁体   English

如何在SELECT语句中以列名作为参数调用用户定义的函数?

[英]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_addresstblInfo的列。

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.

相关问题 将用户定义的 function 在 select 语句中与 INSERT 结合使用 - Using a user-defined function in select statement on a column in conjunction with INSERT 在Oracle用户定义的函数中编写select语句 - Writing a select statement inside an Oracle user-defined function 是否可以在用户定义的函数中将列作为参数插入? - Is it possible to insert a column as a parameter in a user-defined function? 如何在标量类型用户定义的 function 中编写 SQL select 语句? - How can I write SQL select statement inside scalar type user-defined function? 找不到列或用户定义的函数或聚合,或者名称不明确 - cannot find column or the user-defined function or aggregate, or the name is ambigous Hivesql 中 select 语句中的用户定义列名 - User Defined Column name in select statement in Hivesql 自定义函数排序列问题 - User-defined function sorting column problem 用户定义的SQL函数给出错误“无效的列名'Employee_Name'。” - user-Defined SQL Function gives error “Invalid column name 'Employee_Name'.” 我可以从列CHECK约束中调用用户定义的函数吗? - Can I call a user-defined function from a column CHECK constraint? 找不到列“ dbo”或用户定义的函数或聚合“ dbo.GetUserBranchIDs”,或者名称不明确 - Cannot find either column “dbo” or the user-defined function or aggregate “dbo.GetUserBranchIDs”, or the name is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM