[quoted text, click to view] "Christopher Benson-Manica" <ataru@nospam.cyberspace.org> wrote in message
news:bjann8$o7o$1@chessie.cirr.com...
> Christopher Benson-Manica <ataru@nospam.cyberspace.org> spoke thus:
>
> > DECLARE @Date datetime (right?)
> > ???
> > EXEC usp_AddRequest 313,'E',@Date,'QUAL'
> > ^^^^^ <- this is the parameter that wants to
be a
> > datetime
>
> Okay, this one's straight out of the transact SQL book, and it doesn't
work
> either...
>
>
> SET @Date=CAST('1999-01-17 11:47:40' AS datetime)
>
> It insists that it can't convert a varchar to a datetime... whyyyyy? :(
>
> --
> Christopher Benson-Manica | Jumonji giri, for honour.
> ataru(at)cyberspace.org |
The format of your date string is not always recognized correctly by SQL
Server:
declare @date datetime
/* Conversion error */
set dateformat dmy
set @date = CAST('1999-01-17 11:47:40' AS datetime)
select @date
/* No conversion error */
set dateformat mdy
set @date = CAST('1999-01-17 11:47:40' AS datetime)
select @date
Both the following formats are 'safe' and always interpreted consistently by
SQL Server, so using either one will work for you:
'1999-01-17T11:47:40'
'19990117 11:47:40'
To answer your previous post, this should work:
DECLARE @Date datetime
SET @Date = getdate()
EXEC usp_AddRequest 313,'E',@Date,'QUAL'
In this case, date formatting is irrelevant because you are always working
with datetime values.
Simon