Case statement in where clause ??
Hello gurus,
Can we use case statements in where clause ?? Any example will be great!
And also i would like to know, besides CASE and DECODE statements, Is there any way we can use IF ELSE statements in SELECT clause or in WHERE clause ?
Thank you!!
Hi,
user642297 wrote:
Hoek,
Thanks for the reply
Whatever you return from 'then' should match your criteria.I didnt get this part...can you elaborate this part ?? Thank you!!Remember what a CASE expression does: it returns a single value in one of the SQL data types (or NULL).
You're probably familiar with conditions such as
WHERE col = 1Inthe example above, col could be replaced by any kind of expression: a function call, and operation (such as "d * 24") or a CASE expression, which is exactly what Hoek posted:
where case
when col = 6 then 1
when col = 9 then 1
end = 1;I think what Hoek meant about mnatching was this: since the CASE expression is being compared to a NUMBER, then every THEN clause (as well as the ELSE, if there is one) should return the same data type. You can't have one THEN clause return a NUMBER, and another one in the same CASE expression return a DATE, like this:
where case
when col = 6 then 1
when col = 9 then SYSDATE -- WRONG! Raises ORA-00932: inconsistent datatypes
end = 1;
By the way, it's rare when a CASE expression really helps in a WHERE clause. CASE is great for doing conitional stuff in places where you otherwise can't (in the ORDER BY clause, for example), but the WHERE clause was designed for conditions.
Hoek was just trying to give a simple example. If you really wanted those results, it would be simpler to say:
where col = 6
or col = 9and simpler still to say
where col IN (6, 9)
Similar Messages
-
Case statement within where clause
How can i write a case statement within Where clause of SQL statement.
Ex:
If sysdate is less than Dec 31 of 2009 then run the query for 2009 else run the query for 2010.
belwo query is not working. Please let me know how can i write a case statement within where clause.
Select * from table
where
Case
when to_char(sysdate,'yyyymmdd')<=20091231 then tax_year=2009
else tax_year=2010
EndHi,
You can get the results you want like this:
Select *
from table
where tax_year = Case
when to_char(sysdate,'yyyymmdd') <= 20091231
then 2009
else 2010
End
;A CASE expression returns a single value in one of the SQL data types, such as a NUMBER, VARCHAR2 or DATE. There is no boolean type in SQL. -
How to use a case statement in where clause
Hi All,
I have a requirement which is to bring all the claims that are created in the last month.So, i wrote a query something like this
select * from claims
where
(Month(ClaimOpenDate) = Month(Getdate())-1 and year(claimopendate) = year(getDate()))
which would give me any new claims created in last month of current year, but this condition fails if we are in the first month of a new year( lets say if we are in 2016 jan then month(getdate())-1 would be 0 and year(getdate()) would be 2016 so we dont
find any records where year is 2016 and month is 0 for claimopen).
So, i would like to use a case statament or something which can help me get around this one.
Can someone please help me with any suggestions?
ThanksHi Jason,
Thanks a lot for your help. This is what exactly i am looking for but i just gave a sample query above below is my original query
select
row_number() over (order by [ClaimNumber]) as DataElementName
,c.PolicyNumber as PolicyNum
, c.FirstName as CustNameF
,c.LastName as CustNameL
,c.PolicyForm as PolType
,'Homesite' as Company
,[ClaimNumber] as ClaimNum
,E.office as Ofc
,e.Supervisior_FullName as Team
, RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
, case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
,e.AdjusterID as RepC -- not sure
,CONVERT ( varchar,c.LossDate ,101) as DOL
,convert (varchar,c.ClaimOpenDate,101) as DOR
,rtrim(c.Loss_State) as LossSt
,c.Loss_ZipCode as LossZIP
,c.Loss_City as LossCity
,c.LossType as FOL
,'' as PR
,'' as PRNum
,1 as FeaNum
,'HO' as FeaType
,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
,'' as FeaOpen
,'' as FeaClosed
,s.PaymentIndemnityAmount as PaidAmt
,s.ReserveIndemnityAmount as Reserve
,'' as Sub
,'' as Sal
,'' as FeatOwnOfc
,e.Supervisior_FullName as FeatOwnTeam
,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
,e.AdjusterID as FeatOwnRepCode
,NULL AS Description --not sure
from [Stg].[HS_DW_RV_Claims] c
inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
where c.LoadSource = 'CMS'
and
(s.PaymentIndemnityAmount <>0 or s.PaymentExpenseAmount <>0)
and
ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
UNION ALL
select
row_number() over (order by [ClaimNumber]) as DataElementName
,c.PolicyNumber as PolicyNum
, c.FirstName as CustNameF
,c.LastName as CustNameL
,c.PolicyForm as PolType
,'Homesite' as Company
,[ClaimNumber] as ClaimNum
,E.office as Ofc
,e.Supervisior_FullName as Team
, RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
, case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
,e.AdjusterID as RepC -- not sure
,CONVERT ( varchar,c.LossDate ,101) as DOL
,convert (varchar,c.ClaimOpenDate,101) as DOR
,rtrim(c.Loss_State) as LossSt
,c.Loss_ZipCode as LossZIP
,c.Loss_City as LossCity
,c.LossType as FOL
,'' as PR
,'' as PRNum
,1 as FeaNum
,'HO' as FeaType
,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
,'' as FeaOpen
,'' as FeaClosed
,s.PaymentIndemnityAmount as PaidAmt
,s.ReserveIndemnityAmount as Reserve
,'' as Sub
,'' as Sal
,'' as FeatOwnOfc
,e.Supervisior_FullName as FeatOwnTeam
,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
,e.AdjusterID as FeatOwnRepCode
,DESCRIPTION --not sure
from Stg.IG_Document D
inner join [Stg].[HS_DW_RV_Claims] c on D.PARENTREF = C.ClaimNumber
inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
where c.LoadSource = 'CMS'
and
DESCRIPTION like '%Denial Letter%'
and
ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
So if i use your logic in the end for both the where clauses its been more than 10 minutes and the query is still running however if i use my old method it doesnt even take a second. Looks like its affecting the execution plan. Any suggestions to get around
this one please?
Thanks -
Case statement with where clause.
I appreciate that there are much simpler ways to run this query but I wondered if anyone else had come across the following -
select distinct
product_table.a,
product_table.b,
product_table.c,
CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'
WHEN product_table.b = 'B' THEN 'BBB'
WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
WHEN product_table.b IN ('D','DD') THEN 'DDD'
WHEN product_table.b LIKE 'E%' THEN 'EEE'
WHEN product_table.b LIKE 'F%' THEN 'FFF'
WHEN product_table.b LIKE 'G%' THEN 'GGG'
ELSE 'UNKNOWN' END
from product_table
where
( CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'
WHEN product_table.b = 'B' THEN 'BBB'
WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
WHEN product_table.b IN ('D','DD') THEN 'DDD'
WHEN product_table.b LIKE 'E%' THEN 'EEE'
WHEN product_table.b LIKE 'F%' THEN 'FFF'
WHEN product_table.b LIKE 'G%' THEN 'GGG'
ELSE 'UNKNOWN' END) = 'FFF'
when this query runs its as if the where clause = 'FFF' does not exist and all rows are returned.
Thanks, Sarah.Technical questions should be addressed to one of the technical forums. You'll probably find that the folks in the PL/SQL forum (Products | Database | PL/SQL) have some thoughts.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Using Case Statement in Where Clause
Hello All,
I wish to conditionally use different columns for retrieving unique row. This will be dependent upon a parameter passed to the Function/Procedure.
The SQL framed looks as below:
+select *+
from Test_Table
where column_1 = <some_value>
and case when p_call_location = 'A' then column_2 like '%ABC%'
when p_call_location = 'B' then column_2 Not Like '%ABC%'
when p_call_location = 'C' then column_3 like '%EFG%'
when p_call_location = 'D' then column_3 like '%IJKL%'
END;
However, I am not sure if this works, as I am getting a Missing Right Paranthesis error. Major hinderance is the depedency on multiple columns, which would need to be referred for particular scenario.
Can somebody please help me with an example or a skeleton of how a query should be formed?
Appreciate an early reply!!!HI,
i think this may solve your issue...get back to me if u have any qry's on this.
CREATE TABLE Test_Table
(p_call_location VARCHAR2(10),
COLUMN_1 VARCHAR2(20),
COLUMN_2 VARCHAR2(20),
COLUMN_3 VARCHAR2(20))
INSERT INTO Test_Table VALUES('A','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('A','COMNVAL','PER','XXXX');
INSERT INTO Test_Table VALUES('B','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('B','COMNVAL','PER','XXXX');
INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','EFG_XXXX');
INSERT INTO Test_Table VALUES('C','COMNVAL','ABC_PER','XXXX');
INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','EFG_XXXX_IJKL');
INSERT INTO Test_Table VALUES('D','COMNVAL','ABC_PER','GGG_XXXX');
SELECT * FROM Test_Table WHERE ROWID IN (
select case when p_call_location = 'A' AND column_2 like '%ABC%' THEN ROWID
when p_call_location = 'B' AND column_2 Not Like '%ABC%' THEN ROWID
when p_call_location = 'C' AND column_3 like '%EFG%' THEN ROWID
when p_call_location = 'D' AND column_3 like '%IJKL%' THEN ROWID
END AS KK
from Test_Table
where column_1 = 'COMNVAL');
even u can use the below qry also
select *
from test_table
where column_1 = 'COMNVAL'
and (case when p_call_location = 'A' and column_2 like '%ABC%' then 'VALID'
when p_call_location = 'B' and column_2 Not Like '%ABC%' then 'VALID'
when p_call_location = 'C' and column_3 like '%EFG%' then 'VALID'
when p_call_location = 'D' and column_3 like '%IJKL%' then 'VALID'
else 'INVALID'
END) = 'VALID';
thanks
prasuna.
Edited by: user13820845 on Feb 21, 2011 10:25 PM -
How to use CASE stmt in Where clause
Hi,
How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........Hi,
1004977 wrote:
Hi,
How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
See the forum FAQ {message:id=9360002}
Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy. -
CASE in a WHERE clause : ORA-00905
Hi everyone,
I am trying to use a CASE in a WHERE clause and I got the error ORA-00905: missing keyword. Here is my code :
SELECT id_reserv,
concat(nom,concat('_',indice)) as nom,
libelle,
num_lot,
resa_keyword1,
resa_keyword2,
resa_keyword3,
resa_keyword4,
date_creation,
comm_creation,
id_util,
actif,
id_env_act,
(SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util,
(SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env,
(SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp,
(SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif
FROM reservation r
WHERE r.nom NOT LIKE 'RESERV_LOT_%'
AND id_util='1'
AND actif='1'
AND id_env_act>='-1'
AND CASE sansdemande
WHEN true THEN id_reserv not in select id_reserv from demande_livraison where id_env_dep>='-1'
ELSE id_reserv=id_reserv
END
AND nom LIKE '%'
ORDER BY date_creation;
I already looked at the CASE statement and it seems that the syntax is correct, so I'm not sure I can use it in a WHERE clause.
Any help would be nice !
GuichHi,
it should be something like this:
AND CASE
WHEN 'false'='true' THEN (select id_reserv from demande_livraison where id_env_dep>='-1')
ELSE id_reserv
END = id_reserv The subquery should give one row back
But I think it is better to write your query as:
SELECT id_reserv,
concat(nom,concat('_',indice)) as nom,
libelle,
num_lot,
resa_keyword1,
resa_keyword2,
resa_keyword3,
resa_keyword4,
date_creation,
comm_creation,
id_util,
actif,
id_env_act,
(SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util,
(SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env,
(SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp,
(SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif
FROM reservation r
WHERE r.nom NOT LIKE 'RESERV_LOT_%'
AND id_util='1'
AND actif='1'
AND id_env_act>='-1'
AND
( 'false'='true' and id_reserv not in (select id_reserv from demande_livraison where id_env_dep>='-1')
or
( 'true'= 'true' and id_reserv=id_reserv
AND nom LIKE '%'
ORDER BY date_creation;This coding in SQL something as if a=b then c, else d in the simplest form.
Herald ten Dam
http://htendam.wordpress.com -
CASE Statement in Where Condition with Multi Valued parameter in SSRS
Hi All,
I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
SELECT
Logic here
WHERE
Date IN (@Date)AND
(CASE
WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
WHEN ABC_ID IS NULL THEN 'GROUP3'
ELSE 'GROUP4'
END ) IN (@GROUP)
So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
For @Date one dataset will pass the available and default values and
for @GROUP parameters, another dataset will pass the available and default values.
But this is not working as expected. Please suggest me where I am making mistake in the query.
Maruthu | http://sharepoint-works.blogspot.comHi Maruthu,
According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Using :case when in where clause
Hello,
I need some help with using of case statement in a where clause
Table that contains info about employees taking some coursework:
Class (values could be SAP, ORACLE, JAVA)
Code (if Class is SAP then CODE is not null; if class is any other CODE is NULL)
Start Date (date they began class not null)
End Date (date then ended the class - could be null)
Employee Level(numbers from one through five)
I need a single LOV in forms that should show Employee_Level for input class,code,date.
How to do this?
I started off with this but get 'missing statement error'
select distinct employee_level from e_course
where (
case when &class='SAP' then code ='1' and start_date > to_date('20000101','YYYYMMDD') and
end_date < to_date('20000101','YYYYMMDD')
else
null
end) order by employee_level;ThanksHi,
user469956 wrote:
But all these examples have only one condition for each case.Depending on how you count, all WHERE clauses have only one condition.
I see an example in that thread that has 6 atomic conditions, linked by AND and OR.
I need to check date & code. This is what is causing the error.Why do you want to use a CASE statement?
Why can't you put all your conditions directly iinto a WHERE clause, soemthing like this:
WHERE ( &class='SAP'
AND code ='1'
OR ( start_date > to_date('20000101','YYYYMMDD')
AND end_date < to_date('20000101','YYYYMMDD')
)I said "something like this" because I don't know what you really want to do. -
Hi,
Can anybody direct me to the easiest way to do this in sql?
select
from table
where
if :condition = 1 then fieldA = 'Yes'
else if :condition = 2 the fieldB = 'Yes';
I tried to use the CASE statement, but I don't think I have the syntax correct. Is there another way?
Thanks in advanceIf I am correct and as Todd replied, you can write
select
from table
where ((:condition = 1 and fieldA = 'Yes') or
(:condition = 2 and fieldB = 'Yes') or
(:condition = 3 and fieldC = 'Yes')
and any other condtionsAravind -
No output for XML Publisher Report using CASE/DECODE in Where Clause
Hi,
I've a business requirement to modify an existing report which has two input parameters,
-> p_statcode (Closed Status) which can have values 'Y' or 'N'
-> p_overdue (Overdue Flag) which can have values 'Y' or 'N'
The Overdue Flag is an evaluated column having values of Y/N and it is evaluated as follows,
ONTF_MOD_VAL(NVL (
(TRUNC (SYSDATE)
- (TO_DATE (oe_order_lines.attribute18,
'DD-MON-RRRR')
+ TO_NUMBER (fnd_lookup_values.meaning))),
0
overdue_flagThe user requirement now is they needs to be a third option for parameter p_overdue called ALL,
passing which the output should include records having
p_statcode is Y ELSE p_statcode is N AND p_overdue is Y OR p_overdue is N
In other words records having both Y and N vlaues for Overdue Flag have to be returned irrespective of the value given to Closed Status.
Original where clause in the Data Definition file is as follows,
WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
AND overdue_flag = nvl(:p_overdue,overdue_flag)My modified code is as follows,
WHERE Closed_Status = NVL (:p_statcode, Closed_Status)
AND overdue_flag = (CASE
WHEN :p_overdue = 'Y' THEN 'Y'
WHEN :p_overdue = 'N' THEN 'N'
ELSE overdue_flag
END)
OR
WHERE Closed_Status = NVL (:p_statcode, Closed_Status)
AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)Both approaches have the same problem.
The output is in EXCEL format. The modified query works fine for p_overdue as Y or N but when p_overdue is passed as ALL it returns an empty EXCEL sheet with just the report output column headers.
Any help as to why this is the case ?? What is wrong in my approach ?
Regards,
Vishalnot clear about p_overdue = ALL
which values needed for p_overdue = ALL ?
try smth like
WHERE Closed_Status = NVL (:p_statcode, Closed_Status)
AND (
overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
or
:p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
)for overdue_flag which has more then 'Y', 'N' values
if overdue_flag only in ('Y','N') then
WHERE Closed_Status = NVL (:p_statcode, Closed_Status)
AND (
overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
or
:p_overdue = 'ALL'
) -
How to use case function in where clause
Hi,
Suppose a table DEMO has columns
DEMO TABLE
user_id
user_name
location
In this table i have 15 users. but out of 15 users i want to use only 5 users for passing as user_name.
then how to achieve the result
1. when i pass the particular 5 user_name in where clause then i should get all the user_name and for other 10 users it will show only the passing user_name.
how to use case functionDo you mean this ?
SQL> var name varchar2(10)
SQL> exec :name := 'ALLEN'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'SMITH'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'BLAKE'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
BLAKERgds. -
i insert the below rows in a table cash_book.
PRJ_CODE PRJ_NAME
1203 SHIFA
1203 SHIFA
1203 SHIFA
1202 FATIMA
1202 FATIMA
1203 SHIFA
if i select 1202 code then return 1202 code rows, if i select 1203 then returns 1203 code rows, if i select other than both values then returns all rows. how can i define in one query with use (case or decode function) in where clause ??perhaps something like this:
create table test
as
select 1200 + rownum prj_code
from dual
connect by level <= 10;
select * from test;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
var v_PRJ_CODE number
exec :v_PRJ_CODE := 1200;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
exec :v_PRJ_CODE := 1203;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1203Regards
Martin -
Case expression in where clause
I have requirement to select a columns based on condition Datacode should (when the column id=1 THEN 'GILL' ELSE WHEN ID=11 THEN IT Should be 'HEL'
how can i write in case statment
AND DATA_CD =CASE WHEN ID=1 THEN 'GIL'
WHEN ID=11 THEN 'HEL'
END ) my question is above code is corrrect for where clause?
what happens to the ELSE PART?
Please clarify
Soraclehema wrote:
I have requirement to select a columns based on condition Datacode should (when the column id=1 THEN 'GILL' ELSE WHEN ID=11 THEN IT Should be 'HEL'
how can i write in case statment
AND DATA_CD =CASE WHEN ID=1 THEN 'GIL'
WHEN ID=11 THEN 'HEL'
END ) my question is above code is corrrect for where clause?
what happens to the ELSE PART?It is for you to tell what happens to the ELSE part.
If the ID is not 1 or 11, then your AND condition fails and probably your query will not retrieve any records for you (Assuming this query is not a part of OR condition, because there is no query provided.).
Because, without ELSE, the default shall be set to NULL and since you used "DATA_CD =", NULL shall not equate with it resulting in failure of condition. Hence, I would suggest you to add some default value in the ELSE part. -
Delete statement with where clause
Please tell me delete statement for deleting database records from a table with a where clause comprising on composit primary key.
Eg:-
How to delete from employee where a=1, b=1, c=1. Employee also have other columns like name,address etc.
Kindly reply?857452 wrote:
kindly give me example.There are examples in the manual.
Maybe you are looking for
-
Service binded on only one ethernet interface
Hello everyone. I am stuck with a little problem on Snow Leopard Server. I want to open an auxiliary ssh server on the port 443, so I duplicated the /System/Library/LaunchDaemons/sshh.plist I modified the label with a new name and set the socketName
-
User exit for before creating PO
Hello Experts, I have one a requirement when the customer creating the PO, before save free charge(UMSON) filed is automatically active(check the check box) for particular vendor, I done the implicit enhancement for the Tcode ME21its working fine but
-
Connecting iPod to Cassette adaptor or other speaker device?
Hi, i was wondering if someone could help me. I have got a cassette adaptor and a speaker for the iPod nano. They work when i use them with the 2nd Gen nano but don't work with the 3rd Gen nano. Could somebody help me? Thans in advance
-
DataGrid highilght problem with ItemRendered Text
I have a datagrid with some elements that are defined as using an itemrenderer: <mx:DataGrid id="dg" dataProvider="{dp}" > <mx:columns> <mx:DataGridColumn headerText="header" dataField="element" itemRenderer="dgRenderer" /> Now, the item renderer jus
-
I've been struggling with this TC for a day now. I set up a network to access the internet, get it working for a minute, then it drops out, can't find it again, then it does, re-enter my password, and it won't connect. Keep getting timed out message.