Re: Weird Cast operator
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 09/16/04
- Next message: Mark H: "Forcing NOLOCK Hint for given Users"
- Previous message: David Portas: "Re: Dynamic sql querying??"
- In reply to: Ganesan Rajaraman: "Re: Weird Cast operator"
- Next in thread: Ganesan Rajaraman: "Re: Weird Cast operator"
- Reply: Ganesan Rajaraman: "Re: Weird Cast operator"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 16 Sep 2004 23:25:24 +0200
On 16 Sep 2004 13:22:06 -0700, Ganesan Rajaraman wrote:
>1. Try making @in string contain '003' (instead of '00-3'. You will
>notice that both sqls work. From this, we know that trying to return
>int type is not the problem.
Hi Ganesan,
That's not correct. The implicit conversion of '003' to integer will
succed and result in the value 3; the implicit conversion of '0-03' to
integer will fail and result in an error message.
>2. Now, I guess my question is, even when we have
> CAST(CAST(@in AS INT) AS VARCHAR(6))
>(like in the first sql in my posting), server has to do CAST(@in AS
>INT) in order evaulation the whole expression, right. Why doesn't it
>give a syntax error while trying to do that?
Because this CAST is in the THEN clause of the CASE; it will only be
evaluated if WHEN RTrim(LTrim(@in)) NOT LIKE '%[^0-9]%' is true. For the
string value '003', it is (and conversion works flawlessly); for the
string value '0-03', the WHEN part is false and the ELSE part will be
evaluated instead.
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Mark H: "Forcing NOLOCK Hint for given Users"
- Previous message: David Portas: "Re: Dynamic sql querying??"
- In reply to: Ganesan Rajaraman: "Re: Weird Cast operator"
- Next in thread: Ganesan Rajaraman: "Re: Weird Cast operator"
- Reply: Ganesan Rajaraman: "Re: Weird Cast operator"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|