Help to set local variable equal to value of field in result set

Help to set local variable equal to value of field in result set

Post by Pau » Sat, 24 Aug 2002 00:52:22



Hi,

I have a table in my database where I store some of my application
settings. The table has 2 NVARCHAR columns; key_name and key_value.
One of the keys is a date. In a stored procedure how can I set a local
variable of type DATETIME to a key_value which is stored as NVARCHAR.

For example:



N'MyDateKey'))

Thanks Paul

 
 
 

Help to set local variable equal to value of field in result set

Post by adpx » Sat, 24 Aug 2002 04:06:59


Paul,

Please see the old convert() function, or the new cast() function introduced
in SQL Server 7.

--A

 
 
 

Help to set local variable equal to value of field in result set

Post by BP Margoli » Sat, 24 Aug 2002 08:48:08


A,

FYI, the CAST function was available in SQL Server 6.5 ... it might also
have been available in SQL Server 6.0, but I'm not sure about that.

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.


Quote:> Paul,

> Please see the old convert() function, or the new cast() function
introduced
> in SQL Server 7.

> --A

 
 
 

Help to set local variable equal to value of field in result set

Post by Erland Sommarsko » Sun, 25 Aug 2002 06:03:03



> FYI, the CAST function was available in SQL Server 6.5 ... it might also
> have been available in SQL Server 6.0, but I'm not sure about that.

When I do

   select cast(getdate() as varchar)

on a 6.5 server I get:

   Server: Msg 195, Level 15, State 10, Line 1
   'cast' is not a recognized built-in function name.

However, when running on SQL2000 server and setting the compatibility
mode to 65, cast() is accepted.

--
Erland Sommarskog, SQL Server MVP

Books Online (updated!) for SQL 2000 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 
 
 

Help to set local variable equal to value of field in result set

Post by BP Margoli » Sun, 25 Aug 2002 06:17:49


Erland,

I, obviously, don't have SQL Server 6.5 on my machine anymore, but I did
check the index of "Inside Microsoft SQL Server 6.5" before posting, and
there was a reference to the CAST function in it, so I assumed the function
existed in SS6.5.

My error  :-(    Thanks for the correction.

BPM



> > FYI, the CAST function was available in SQL Server 6.5 ... it might also
> > have been available in SQL Server 6.0, but I'm not sure about that.

> When I do

>    select cast(getdate() as varchar)

> on a 6.5 server I get:

>    Server: Msg 195, Level 15, State 10, Line 1
>    'cast' is not a recognized built-in function name.

> However, when running on SQL2000 server and setting the compatibility
> mode to 65, cast() is accepted.

> --
> Erland Sommarskog, SQL Server MVP

> Books Online (updated!) for SQL 2000 at
> http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp