473,396 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

usage of CASE statement

Hi,
I am trying to use the CASE statement in select...But i am getting errors...My query is like

Expand|Select|Wrap|Line Numbers
  1. select 
  2. Case CHARINDEX(':',columnname)
  3. When 0
  4. THEN'columnname'
  5. ELSE
  6. SubString('columnname',CHARINDEX(':','columnname')-1,LEN('columnname'))
  7. END
  8. as column1
  9. from table1
  10. where column1= 'xyz'
For the above i am getting an error ORA00904(Invalid column name). Kindly shed some light on the usage of case statement in the column name..
The logic behind the code is i have a column in which i may get either constant or a value with delimiters like a.b.c:d(length is not constant). So if it is a constant i will fetch the whole value...if it is a value with delimiter i will take the character from the character which is previous to the ":"
Sep 15 '11 #1
3 2174
Rabbit
12,516 Expert Mod 8TB
Why is your columnname field surrounded by single quotes?
Sep 15 '11 #2
debasisdas
8,127 Expert 4TB
CHARINDEX is not a inbuilt function is Oracle, it is used in Ms Sql Server. The corresponding Oracle function is INSTR.
Sep 18 '11 #3
@rabbit:-u r right.......it should not be surrounded by '.
this statement
Expand|Select|Wrap|Line Numbers
  1. select CHARINDEX(':',name) from oracle
is working fine, but if i put the same inside the case like the below
Expand|Select|Wrap|Line Numbers
  1. Select
  2. Case CHARINDEX(':',name)
  3. When 0 --Type1
  4. THEN name
  5. ELSE
  6. SubString(name,CHARINDEX(':',name)-1,LEN(name))
  7. END
  8. as column1
i am getting an error saying name is an invalid column name.......



@debasisdas:- ok thanks will try it............
Sep 18 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom | last post by:
I would like to know if an .asp case statement can contain HTML elements. I am building an application that I would like to have dynamic choices. The dynamic part would be built in the a case...
6
by: ryan.mclean | last post by:
Hi all, first, let me preface this by saying that I am very new to sql server, coming from oracle. Here is my problem: I would like to have a case statement (similar to decode in oracle) that...
21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
2
by: Mark Mullins | last post by:
have code below: Function ClassColl(strClass As Variant, strColl As Variant) As String ' Comments : ' Parameters : strClass ' strColl ' Returns : String Description '...
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
7
by: atrottier | last post by:
Is it possible within Access 2003 to use a Case statement in the query sql that returns info for a report. I mostly work with a Sybase database system which allows such commands. Can't find any...
2
by: jobinjee | last post by:
i use the case statement but it always show that an error near the case.... my usage is select category = case when qtysold is 12 then 'sorry' --when 'Band' then 'Wrist Band' ...
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.