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

时间:2020-12-08 16:36:52

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

我有一个SQL函数,它接受一个String,一个DATE和另一个字符串。

 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.

将数据类型nvarchar转换为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?

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

2 个解决方案

#1


2  

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();

#2


1  

Use GetDate() instead of NOW

使用GetDate()而不是NOW

Update I just notice you said DATE not DATETIME so try

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

convert(date, GetDate())

#1


2  

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();

#2


1  

Use GetDate() instead of NOW

使用GetDate()而不是NOW

Update I just notice you said DATE not DATETIME so try

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

convert(date, GetDate())