Welcome Guest Search | Active Topics | Log In | Register

Specific cast is invalid Options
yishai
#1 Posted : Sunday, June 21, 2009 5:24:06 PM
Rank: Member

Groups: Member

Joined: 6/13/2009
Posts: 3
Points: 9
Location: Israel
you have a bug in CASE Statement the following will return an invalid cast


DECLARE @i int
SET @i=5
SELECT (CASE WHEN @i>0 THEN @i ELSE 0 END)
js_vistadb
#2 Posted : Monday, June 22, 2009 3:25:36 PM
Rank: VistaDB Staff

Groups: Administration, VistaDB Staff

Joined: 8/13/2006
Posts: 3,362
Points: 3,891
Location: Mount Dora, Florida
I think that case promotes all values to BigInt internally. So will probably have to declare your variable as a BigInt to run like that.

We do already have this marked as a problem, but to change the internal behavior might break lots of users apps because they are expecting that behavior.

Jason Short

yishai
#3 Posted : Monday, June 22, 2009 4:45:45 PM
Rank: Member

Groups: Member

Joined: 6/13/2009
Posts: 3
Points: 9
Location: Israel
If you are promoting to Bigint I would expect an implicit cast from int.
Regardless I think you need a better error message or to flag this as an SQL error, i encountered this issue at runtime when executing a large SP, and the debugging process was painful.

js_vistadb
#4 Posted : Monday, June 22, 2009 5:02:12 PM
Rank: VistaDB Staff

Groups: Administration, VistaDB Staff

Joined: 8/13/2006
Posts: 3,362
Points: 3,891
Location: Mount Dora, Florida
Agreed - the error message is painful. But that is the error message from .Net on the conversion. It will not convert it through a simple cast. You have to call Convert.Toxxxx() for it to work and the code at that point is all generic (doesn't know what the types are and is trying to use implicit casting).

Jason Short

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.064 seconds.