将数据类型 nvarchar 转换为 datetime 时出错
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://msdn.microsoft.com/en-us/library/ms189915.aspx
http://msdn.microsoft.com/en-us/library/ms189915.aspx
使用
GetDate()
而不是NOW
更新我只是注意到你说的是 DATE 而不是 DATETIME 所以尝试
Convert(date, GetDate())
Use
GetDate()
instead ofNOW
Update I just notice you said DATE not DATETIME so try
convert(date, GetDate())