将数据类型 nvarchar 转换为 datetime 时出错

发布于 2024-10-01 20:47:18 字数 581 浏览 0 评论 0原文

我有一个 SQL 函数,它接受一个字符串、一个日期和另一个字符串。

 EXEC  dbo.ReplaceString 'You ve been subscribed to the ##company## newsletter.',
NOW,'BIG DEES'  


CREATE Function [dbo].[ReplaceString]
(
            @main_message As Varchar(500), 
            @date_sent As DateTime, 
            @company As Varchar(30)

)
RETURNS VARCHAR(650)
AS 
BEGIN 


         RETURN(@main_message)

 END

问题是,当我尝试执行此函数时,即使注释掉函数中的所有代码处理逻辑,我也会收到错误

将数据类型 nvarchar 转换为日期时间时出错。

我没有对任何数据进行任何数据访问函数中的种类。我所拥有的只是使用传入的其他信息处理字符串的代码。任何人都知道这个问题可能来自什么以及我如何解决它?

I have an SQL Function that takes a String, a DATE and another string.

 EXEC  dbo.ReplaceString 'You ve been subscribed to the ##company## newsletter.',
NOW,'BIG DEES'  


CREATE Function [dbo].[ReplaceString]
(
            @main_message As Varchar(500), 
            @date_sent As DateTime, 
            @company As Varchar(30)

)
RETURNS VARCHAR(650)
AS 
BEGIN 


         RETURN(@main_message)

 END

Problem is when I try to execute this function, even after commenting out all code processing logic in my function, I get the error

Error converting data type nvarchar to datetime.

I am not doing any data access of any kind in the function. All I have is code to process the string using the other information passed in.Anyone have an idea of what this problem could be from and how I can fix it?

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

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

发布评论

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

评论(2

北方的韩爷 2024-10-08 20:47:18

http://msdn.microsoft.com/en-us/library/ms189915.aspx

-- Try to use a function as a parameter value.
-- This produces an error message.
EXEC dbo.uspGetWhereUsedProductID 819, GETDATE();

http://msdn.microsoft.com/en-us/library/ms189915.aspx

-- Try to use a function as a parameter value.
-- This produces an error message.
EXEC dbo.uspGetWhereUsedProductID 819, GETDATE();
恏ㄋ傷疤忘ㄋ疼 2024-10-08 20:47:18

使用 GetDate() 而不是 NOW

更新我只是注意到你说的是 DATE 而不是 DATETIME 所以尝试

Convert(date, GetDate())

Use GetDate() instead of NOW

Update I just notice you said DATE not DATETIME so try

convert(date, GetDate())

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