无法从 select ... from table 语句调用标量值 CLR UDF

发布于 2024-07-27 03:14:41 字数 442 浏览 2 评论 0原文

我创建了一个标量值 CLR UDF(用户定义函数)。 它需要一个时区 ID 和一个日期时间,并返回转换为该时区的日期时间。

我可以通过简单的选择来调用它,没有任何问题: "select dbo.udfConvert('浪漫标准时间', @datetime)" (@datetime 当然是一个有效的日期时间变量)

但是如果我调用它从表中传递日期时间它就会失败: “从某个表中选择 dbo.udfConvert('浪漫标准时间', StartTime)” (StartTime列当然是datetime类型的列)

错误信息是: “找不到列“dbo”或用户定义函数或聚合“dbo.udfConvert”,或者名称不明确。”

这条消息确实是针对拼写错误的初学者,但由于它在一种情况下有效,而在另一种情况下无效,所以我认为我没有拼写错误。

有任何想法吗?

I have created a scalar-valued CLR UDF (user defined function). It takes a timezone id and a datetime and returns the datetime converted to that timezone.

I can call it from a simple select without problems:
"select dbo.udfConvert('Romance Standard Time', @datetime)"
(@datetime is of course a valid datetime variable)

But if I call it passing in a datetime from a table it fails:
"select dbo.udfConvert('Romance Standard Time', StartTime) from sometable"
(column StartTime is of course a column of type datetime)

The error message is:
"Cannot find either column "dbo" or the user-defined function or aggregate "dbo.udfConvert", or the name is ambiguous."

This message is really for beginners that has misspelled something, but as it works in one case and not in the other, I don't think I have done any misspellings.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日记撕了你也走了 2024-08-03 03:14:41

我发现了问题。 如果我将硬编码时区提取到变量中,则效果很好:

声明@timeZoneID nvarchar(100)

select @timeZoneID='Romance Standard Time'

Select dbo.Convert(@timeZoneID,StartTime) From sometable

显然sql-server无法计算了解如何将硬编码字符串转换为 nvarchar 字符串。

I found the problem. If I extracted the hardcoded timezone out to a variable instead it worked fine:

declare @timeZoneID nvarchar(100)

select @timeZoneID='Romance Standard Time'

Select dbo.Convert(@timeZoneID,StartTime) From sometable

Apparently sql-server could not figure out how to convert the hardcoded string to a nvarchar string.

泪意 2024-08-03 03:14:41

你也可以这样做:

select dbo.udfConvert(N'Romance Standard Time', StartTime) from sometable

如果你没有为Unicode字符串常量添加N前缀,SQL Server会在使用该字符串之前将其转换为当前数据库的非Unicode代码页。 这就是为什么我找不到带有 nvarchar 签名的函数。

you can also do:

select dbo.udfConvert(N'Romance Standard Time', StartTime) from sometable

If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string. That's why i could not find the function with the nvarchar signature.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文