Grigor Aleksanyan
Grigor Aleksanyan

Reputation: 550

SQL: .. contains an unresolved reference to an object

Full message

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]

I know, there is couple of Question already exists with this message. But this one in my example happens especially because of TIME Sql type.

I Have StoredProcedure ( in Visual Studio Sql Database project ) which is looks like this.

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

I have no any table with name TIME. When I change the type TIME with other, it stars work correctly, other way it shows this message in TIME type and compile time error.

TIME I trying to use as a SQL alternative for C#'s TimeSpan.

Upvotes: 0

Views: 478

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062975

You can't use time with SQL Server 2005, since it didn't exist until SQL Server 2008.

Instead, consider storing a numeric representation of the time interval (which is, ultimately, what time is anyway - just: you'd be doing it explicitly rather than automatically). Typical examples would be to store, as an int, the number of seconds or milliseconds represented by your time interval.

Conveniently, TimeSpan has a TotalSeconds and TotalMilliseconds property that maps to this (just: convert it to an integer), and has FromSeconds(...) and FromMilliseconds(...) methods for going the other direction.


From comments, it sounds like you also need features to combine (add) times to dates; this is also easy:

DATEADD(second, {interval as seconds}, {some datetime})

or

DATEADD(millisecond, {interval as milliseconds}, {some datetime})

Upvotes: 2

Related Questions