Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Select Case Statement

Author  Topic 

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 03:09:18
Hi,

I'm here would like to know whether we can have SQL statement with below condition:

Select A, B, C, CASE WHEN A = 0 THEN ((A+B)/2) ELSE 'Proceed' END FinalFigure

Pls advice.

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-06 : 03:12:42
have you tried it already? if you encounter an error then let us know.

--------------------
keeping it simple...
Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 03:27:09
YUP...I have already tried. For ur infor that I'm using Oracle Toad. The Error message I get is "inconsistent datatype".
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-06 : 03:32:39
quote:
Originally posted by wensen

YUP...I have already tried. For ur infor that I'm using Oracle Toad. The Error message I get is "inconsistent datatype".



then check if a and b are numeric types or if their data types allow division

--------------------
keeping it simple...
Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 03:39:39
Oh ya, you are correct, it is in varchar datatype, can it be converted?
Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 03:52:50
I have tried to use CAST as below:

CAST(A AS NUMBER(12,2))

but encounter error...
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-06 : 04:21:49
what's the error?

--------------------
keeping it simple...
Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 06:54:37
same error -> "inconsistent datatype"
Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 08:07:16
something to add..I try to use TO_NUMBER function as below:

select (TO_NUMBER(A)+ TO_NUMBER(B)) FINALTOTAL from TableName

it works......but when put into the CASE statement it having Inconsistant datatype error....

pls advice..
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-12-06 : 15:55:11
You do know that this is a SQL Server site and not an Oracle one...



Brett

8-)

EDIT: Actually Looking at the home page, unless there's an article, it's not readily apparent

Go to Top of Page

wensen
Starting Member

7 Posts

Posted - 2004-12-06 : 20:26:12
YUP, I know it is SQL server forum, but the SQL statement that are using have some similiar feature, that is why I try to join the forum here...
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-12-06 : 22:39:03
in mssql, there is a function called convert or cast to change the data type, look for something similar in oracle


--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -