SQL:..包含对对象的未解析的引用

时间:2018-11-16 12:11:12

标签: c# sql-server-2005

完整消息

Parameter: [DbName].[SpName].@timeout contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [dbo].[TIME]

我知道,此消息已经存在几个问题。但是在我的示例中,发生这种情况尤其是由于TIME Sql类型。

我有如下所示的StoredProcedure(在Visual Studio Sql数据库项目中)。

CREATE PROCEDURE [dbo].[my_sp] 
   @name VARCHAR(255),
   @timeout TIME 
AS
  ...

我没有任何名称为 TIME 的表。当我与其他类型更改TIME类型时,它可以正常工作,以其他方式以TIME类型显示此消息并编译时间错误。

TIME我试图用作C#的TimeSpan的SQL替代方法。

1 个答案:

答案 0 :(得分:2)

您不能在SQL Server 2005中使用time,因为它直到SQL Server 2008才存在。

相反,请考虑存储时间间隔的数字表示形式(最终,time仍然是 -只是:您会明确地而不是自动地进行操作)。典型示例是将时间间隔表示的秒数或毫秒数存储为int

方便地,TimeSpan具有映射到此的TotalSecondsTotalMilliseconds属性(只是:将其转换为整数),并具有FromSeconds(...)和{{1} }用于其他方向的方法。


从评论中看来,您还需要一些功能来组合(添加)时间到日期;这也很容易:

FromMilliseconds(...)

DATEADD(second, {interval as seconds}, {some datetime})
相关问题