Re: Weird Cast operator
From: Ganesan Rajaraman (ganesanrajaraman_at_gmail.com)
Date: 09/16/04
- Next message: Hugo Kornelis: "Re: Parsing CSV Values in a Several Column"
- Previous message: j0ey: "Re: Sql Server 2005/Yukon Notification Services"
- In reply to: David Portas: "Re: Weird Cast operator"
- Next in thread: Hugo Kornelis: "Re: Weird Cast operator"
- Reply: Hugo Kornelis: "Re: Weird Cast operator"
- Messages sorted by: [ date ] [ thread ]
Date: 16 Sep 2004 13:22:06 -0700
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.
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?
3. We did determine that "Cast(Cast(@in as int) as varchar)" works for
our scenario. But, we are only trying to understand **WHY** one works
while the other doesn't.
-Ganesh
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message news:<jsKdnfODHbicatjcRVn-pA@giganews.com>...
> CASE can only return a single datatype. In your second CASE one expression
> is INT and the other VARCHAR. The rules of datatype precedence give INTEGER
> a higher priority than VARCHAR so SQL attempts to convert the string to a
> numeric, which causes an error.
>
> Change the second CASE expression to:
>
> ...
> THEN CAST(CAST(@in AS INT) AS VARCHAR(6))
> ...
- Next message: Hugo Kornelis: "Re: Parsing CSV Values in a Several Column"
- Previous message: j0ey: "Re: Sql Server 2005/Yukon Notification Services"
- In reply to: David Portas: "Re: Weird Cast operator"
- Next in thread: Hugo Kornelis: "Re: Weird Cast operator"
- Reply: Hugo Kornelis: "Re: Weird Cast operator"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|