Monday, March 12, 2012

msg 296 - out of range smalldatetime value

Server: Msg 296, Level 16, State 3, Line 4
The conversion of char data type to smalldatetime data type resulted in an
out-of-range smalldatetime value.
I'm doing a simple select, one of the values is the concatention of a CASE
statement and two other fields. I've got no date specification or range of
any sort in my query, except that one of the fields I am concatenating with
is a date. the relevant portion of the code is here;
...
...
END+A.ctDate+CAST(A.ID AS varchar(12))+'.'+'BB' AS oID
This is the only date I reference at all in the select, and if pulled from
the query, it runs fine. What's the right way to get around msg 296 in this
situation?
-- LynnIf you're concatenating to a string, you should cast it explicitly as a
string.
...
END+CONVERT(CHAR(8), A.ctDate, 112)+CASE ...
"Lynn" <Lynn@.discussions.microsoft.com> wrote in message
news:7FB003B4-F5EB-4FC6-B330-8483A80EA586@.microsoft.com...
> Server: Msg 296, Level 16, State 3, Line 4
> The conversion of char data type to smalldatetime data type resulted in an
> out-of-range smalldatetime value.
> I'm doing a simple select, one of the values is the concatention of a CASE
> statement and two other fields. I've got no date specification or range
> of
> any sort in my query, except that one of the fields I am concatenating
> with
> is a date. the relevant portion of the code is here;
> ...
> ...
> END+A.ctDate+CAST(A.ID AS varchar(12))+'.'+'BB' AS oID
> This is the only date I reference at all in the select, and if pulled from
> the query, it runs fine. What's the right way to get around msg 296 in
> this
> situation?
> -- Lynn|||excellent. that works perfectly. thanks very much
-- Lynn
"Aaron Bertrand [SQL Server MVP]" wrote:

> If you're concatenating to a string, you should cast it explicitly as a
> string.
> ....
> END+CONVERT(CHAR(8), A.ctDate, 112)+CASE ...
>
>
> "Lynn" <Lynn@.discussions.microsoft.com> wrote in message
> news:7FB003B4-F5EB-4FC6-B330-8483A80EA586@.microsoft.com...
>
>

No comments:

Post a Comment