How to use CASE statement in WDA
Hi All,
Can any one Please expain me ' How to use CASE statement in Web dynpro ABAP? '
Please give me an example also.
Thanks in Advance !
Hi,
The usage of case statement in webdynpro is same as used in general ABAP.
Data: l_id type string.
l_id = wdevent->get_string( 'ID' ).
case l_id.
when 'BTN1'.
when 'BTN2'.
when 'OTHERS'.
endcase.
Regards,
Radhika.
Similar Messages
-
Help: How to use Case statement in Interface ODI11g?
Hi
From my Source base i am getting 'Year' Values and i want translate these values into a code in interface and after translate want to push to Target system.
Example:
From source Database i am getting value for
Year
2010
2011
2012
When i get Year 2010 i want to modify value into 'FY10'
when i get Year 2011 i want to modify value into 'FY11'
and same for Year 2012 TO 'FY12'
I was trying to do by Case statement but didn't got success.
I dont want to create Lookup table in source system.
Any help in this regards.
Thanks
Regards
Sher
Edited by: Sher Ullah Baig on Aug 26, 2012 5:52 PMCASE
WHEN source_column='2010' THEN 'FY10'
WHEN source_column='2011' THEN 'FY11'
WHEN source_column='2012' THEN 'FY12'
END -
How to use multiple statements inside the "THEN" block of CASE statement?
Below is the code:
SET @strTempString = case @strKeyMode
WHEN 'AUTO/CYCLE'
THEN @strRefID + '|' + @strRetID
WHEN 'CYCLE'
THEN @strRefID + '|' + @strRetID
WHEN 'COMMERCIAL'
THEN @strRefID + '|' + @strRetID
WHEN 'ISNAP'
THEN set @strFName = ltrim(rtrim((Left(dbo.CleanTheStringAdv(@strFName + ' ', 2) + ' ', 2))))
'' + @strRefID + '|' + @strLName + '|' + @strFName + '|' + @strZIPorPolType
WHEN 'ASNAP'
THEN @strRefID + '|' + @strRetID
WHEN 'MOAT'
THEN @strRefID + '|' + @strRetID
else '0'
end
The first 3 conditions are understandable. How to use multiple statements in 4th case?
Here I first want to set the value as:
set @strFName = ltrim(rtrim((Left(dbo.CleanTheStringAdv(@strFName + ' ', 2) + ' ', 2))))
and then return the string '' + @strRefID + '|' + @strLName + '|' + @strFName + '|' + @strZIPorPolType to @strTempString.
Please help me remove the syntax errors.
Thanks in advance.Try below SQL
DECLARE @strKeyMode varchar(20) = 'ISNAP'
DECLARE @SQL VARCHAR(MAX)
DECLARE @strRefID int=1
DECLARE @strRetID INT=2
--FIRST WAY
IF @strKeyMode ='AUTO/CYCLE'
SELECT CAST(@strRefID as varchar(10))
ELSE IF @strKeyMode ='CYCLE'
SELECT @sql = CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))
ELSE IF @strKeyMode='ISNAP'
SELECT @sql = CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))+'test'+'abc'
ELSE
SELECT @SQL='ABC'
print @sql
----SECOND WAY
SELECT @SQL = CASE @strKeyMode
WHEN 'AUTO/CYCLE' THEN CAST(@strRefID as varchar(10))
WHEN 'CYCLE' THEN CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))
WHEN 'ISNAP' THEN CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))+'test'+'abc'
ELSE 'No Record'
END
PRINT (@SQL)
--Prashanth -
How to use union statement with declare & set function?
Hi Experts,
i have small query about how to use union statement with declare & set function?
Example as below :
DECLARE @name AS date
Declare @name2 AS date
/* SELECT FROM [2013].[dbo].[OINV] T0 */
/* WHERE */
SET @name = /* T0.DocDate */ '[%1]'
SET @name2 = /* T0.DocDate */ '[%2]'
select '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2013.dbo.orct t1
inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2013.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]
Union
/* SELECT FROM [2014].[dbo].[OINV] T0 */
/* WHERE */
SET @name = /* T0.DocDate */ '[%1]'
SET @name2 = /* T0.DocDate */ '[%2]'
select '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2014.dbo.orct t1
inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2014.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]You have to create stored procedure in SQL only .
Like u must have create for Crystal .
You can execute procedure in query manager but you have to enter parameter manually..
example
Exec @Test '20140101' '20140501'
Every time user has to enter it manually in yyyymmdd format in case of date parameters.
Example
Create Proc [@Test]
as begin
DECLARE @name AS date
Declare @name2 AS date
/* SELECT FROM [2013].[dbo].[OINV] T0 */
/* WHERE */
select '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2013.dbo.orct t1
inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2013.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between @Name and @Name2
Union
/* SELECT FROM [2014].[dbo].[OINV] T0 */
/* WHERE */
select '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
datediff(dd,t3.DocDate,t1.Docdate) as Days
from 2014.dbo.orct t1
inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
left join 2014.dbo.oinv t3 on
t3.docentry = t2.baseAbs
inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
where t2.DcntSum <> 0.000000 and t3.DocDate between
between @Name and @Name2
end -
Using case statement in merge when matched
Hi,
I want to use case statement in the when matched clause of merge statement to ensure that I update only those fields that are undated.
create table TEST1
NAME1 VARCHAR2(25),
NAME2 VARCHAR2(25),
ID NUMBER not null
create table TEST2
ID NUMBER not null,
ID2 NUMBER not null,
NAME1 VARCHAR2(25),
NAME2 VARCHAR2(25)
merge into test1 t1
using
test2 t2
ON (t1.id = t2.id)
when matched
then
case
when t1.name1 != t2.name1
then
update set t1.name1 != t2.name1
when t1.name2 != t2.name2
then
update set t1.name2 != t2.name2
else
null;
end
it does not work and raises invalid sql command. Any idea how can I do that?
Thanks.
Sajid
Edited by: 808255 on Nov 12, 2010 4:22 AMHi
In that case you would have to use multiple statements and you may as well just use UPDATE instead of MERGE. Also, are you sure that you aren't trying to to fix a problem that doesn't actually exist.
Think about where the execution time is going to come from...
I would be tempted to do 1 UPDATE like this...
UPDATE test1 t1
SET (t1.name1,
t1.name2) = (SELECT t2.name1,
t2.name2
FROM test2 t2
WHERE t1.id = t2.id
AND (t1.name1 != t2.name1
OR t1.name2 != t2.name2))If you get specific performance issue with this, then post an explain plan and trace and I'll have a look.
I don't this the cost of the update is going to be as great as you think.
Cheers
Ben -
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. -
Sql proposed to use case statement
Hi All
Can anyone help me here
This code works fine,here inthe inner sub queries(b,c,d,e,f),i am getting the weekly counts of usage data from the table mf_wer_OBI_USAGE_reqq.
As this is hitting same table with the similar set of queries so i was adviced to use case statement by taking the wk_1...5 in variable and making the query better
I am unable to figure out how to proceed.
Appreciate your help here.
Thanks
create table mf_wer_OBI_USAGE_reqq_WK
as select x.user_name id,x.mon MONTH_COUNT,x.wk_1 WEEK1_COUNT,x.wk_2 WEEK2_COUNT,x.wk_3 WEEK3_COUNT,x.wk_4 WEEK4_COUNT,x.wk_5 WEEK5_COUNT,x.subject_area_name,
y.EMP_FIRST_NAME FIRSTNAME,y.EMP_LAST_NAME SURNAME,y.E_MAIL_ADDRESS USER_MAILID,y.ouc OUC
from (select a.user_name,a.mon,a.subject_area_name,b.wk_1,c.wk_2,d.wk_3,e.wk_4,f.wk_5
from (select user_name,sum(count_us_st) mon,subject_area_name from mf_wer_OBI_USAGE_reqq group by user_name,subject_area_name) a,
(select user_name,sum(count_us_st) wk_1,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 1 and 7
group by user_name,subject_area_name) b,
(select user_name,sum(count_us_st) wk_2,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 8 and 14
group by user_name,subject_area_name) c,
(select user_name,sum(count_us_st) wk_3,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 15 and 21
group by user_name,subject_area_name) d,
(select user_name,sum(count_us_st) wk_4,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 22 and 28
group by user_name,subject_area_name) e,
(select user_name,sum(count_us_st) wk_5,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 29 and 31
group by user_name,subject_area_name) f
where a.user_name=b.user_name(+)
and a.subject_area_name=b.subject_area_name(+)
and a.user_name=c.user_name(+)
and a.subject_area_name=c.subject_area_name(+)
and a.user_name=d.user_name(+)
and a.subject_area_name=d.subject_area_name(+)
and a.user_name=e.user_name(+)
and a.subject_area_name=e.subject_area_name(+)
and a.user_name=f.user_name(+)
and a.subject_area_name=f.subject_area_name(+)) x,
dm_employee y
where x.user_name=y.id and
y.active_flg='Y';Swas_fly wrote:
This code works fineIf it's fine, why try to fix it?
Post your table (only the relevant columns as a CREATE TABLE statement) and some sample data (INSERT into) and your required output.
Post your code between these tags: -
Hi
I have two tables
employee
empid empname empaddress valid
Employeedetails
empid empname manager
I would like to validate empname from both the tables using case statement and empid as join and update 'valid' column in employee table to y/n.
Please help me with the syntaxHi,
Depending on your requirements:
UPDATE employee e
SET valid = (
SELECT CASE
WHEN COUNT (*) = 0
THEN 'n'
ELSE 'y'
END
FROM employeedetails
WHERE empname = e.empname
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
If you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Can I use case statements in triggers?
I created this trigger, it works BUT I don't like those parentheses at the begining, I would like
to change those parentheses for case statements, well that is my question, can you use case statements in triggers, how you would translate the following in case statement?
FOR EACH ROW
WHEN ( (new.sgbstdn_levl_code = 'UG')
and
( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
OR
( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
(NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
(OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
==================================================================================================
CREATE OR REPLACE TRIGGER CC_STUD_WITHDRAWAL
AFTER UPDATE OR INSERT ON SATURN . SGBSTDN
FOR EACH ROW
WHEN ( (new.sgbstdn_levl_code = 'UG')
and
( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
OR
( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
(NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
(OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
DECLARE
v_params gokparm.t_parameterlist;
event_code gtveqnm.gtveqnm_code%TYPE;
firstname spriden.spriden_first_name%TYPE;
lastname spriden.spriden_last_name%TYPE;
middlename spriden.spriden_mi%TYPE;
id spriden.spriden_id%TYPE;
CURSOR get_stud_name IS
SELECT
spriden_id ,
spriden_last_name ,
spriden_first_name ,
spriden_mi
FROM
saturn.spriden
WHERE spriden_pidm = :NEW.SGBSTDN_PIDM
AND spriden_change_ind IS NULL;
BEGIN
IF goksyst . f_isSystemLinkEnabled ( 'WORKFLOW' ) THEN
event_code := SUBSTR ( gokevnt.F_CheckEvent ( 'WORKFLOW' ,'CC_STUDENT_WITHDRAW' ),1,20);
OPEN get_stud_name ;
FETCH get_stud_name INTO id , lastname , firstname , middlename ;
CLOSE get_stud_name ;
----pass parameters to the event
v_params ( 1 ).param_value := 'CC_STUDENT_WITHDRAW' ;
v_params ( 2 ).param_value := '' ;
v_params ( 3 ).param_value := 'Student Withdrawal:' || lastname || ',' || firstname || ' ' ||
middlename ;
v_params ( 4 ).param_value := :NEW.sgbstdn_pidm ;
v_params ( 5 ).param_value := id ;
v_params ( 6 ).param_value := lastname ;
v_params ( 7 ).param_value := firstname ;
v_params ( 8 ).param_value := middlename ;
v_params ( 9 ).param_value := :NEW.sgbstdn_term_code_eff ;
v_params ( 10 ).param_value := :NEW.SGBSTDN_STST_CODE ;
v_params ( 11 ).param_value := :NEW.SGBSTDN_STYP_CODE ;
gokparm.Send_Param_List ( event_code , v_Params );
END IF;
END;
/You could delete a fair number of extraneous parentheses.
CREATE OR REPLACE TRIGGER cc_stud_withdrawal
AFTER UPDATE OR INSERT
ON saturn.sgbstdn
FOR EACH ROW
WHEN NEW.sgbstdn_levl_code = 'UG'
AND ( NEW.sgbstdn_stst_code NOT IN ('GR', 'SA', 'AS', 'IS')
OR ( NEW.sgbstdn_stst_code = 'IS'
AND NEW.sgbstdn_styp_code IN ('N', 'T')
AND OLD.sgbstdn_stst_code = 'AS')) -
Checking for the condition types using case statement
hi folks,
I have a lot of condition types that I have to check for and I am using case statement to do that. The code goes like this.
case wac-kschl.
when 'ZRAT' OR 'ZAGR' OR 'ZRCR' OR
'Y098' OR 'Y007' OR 'ZREW' OR 'Y106' OR 'ZTSR' OR 'Y127' OR 'Y125' OR 'Y126' OR 'Y124' OR 'Y157' OR 'Y092' OR 'Y085' OR 'Y090' OR 'ZMZD'
OR 'Y215' OR 'Y214' OR 'Y111' OR 'ZC$D' OR 'ZAUD'.
up till here it is working on errors and when I add few more condition types to the case statement it is throwing the error.
I have to check for all the condition types out here.
How can I correct it? Is there a better way to do it?
thanks
SanthoshHi Santhosh,
I think that your CASE statement has a flaw. The line length of one of the lines is too large. You need to insert a carriage-return to shorten it (or press the button 'Pretty Printer').
The code would look nicer like this:[code] CASE wac-kschl.
WHEN 'ZRAT' OR 'ZAGR' OR 'ZRCR' OR 'Y098' OR 'Y007' OR 'ZREW'
OR 'Y106' OR 'ZTSR' OR 'Y127' OR 'Y125' OR 'Y126' OR 'Y124'
OR 'Y157' OR 'Y092' OR 'Y085' OR 'Y090' OR 'ZMZD' OR 'Y215'
OR 'Y214' OR 'Y111' OR 'ZC$D' OR 'ZAUD' OR 'Z001' OR 'Z002'
OR 'Z003' OR 'Z004' OR 'Z005' OR 'Z006' OR 'Z007' OR 'Z008'
OR 'Z009' OR 'Z010' OR 'Z011' OR 'Z012' OR 'Z013' OR 'Z014'.
Do your thing here
WRITE: / 'OK'.
WHEN OTHERS.
WRITE: / 'NOT OK'.
ENDCASE.[/code]If this will not work for you, you could try a different approach:[code]* Local definition
DATA:
var_list(1024).
Build variable string for checking
CONCATENATE 'ZRAT ZAGR ZRCR Y098'
'Y007 ZREW Y106 ZTSR'
'Y127 Y125 Y126 Y124'
'Y157 Y092 Y085 Y090'
'ZMZD Y215 Y214 Y111'
'ZC$D ZAUD'
INTO var_list
SEPARATED BY space.
Check if the correct value is supplied
IF var_list CS wac-kschl.
Do your thing here
WRITE: / 'OK'.
ENDIF.[/code]Hope this helps you a bit.
Regards,
Rob. -
How to use perform statements in sap scripts
how to use perform statements in sap scripts . and pls send me one progam for this
thnaks
rajaHi Raja,
<b>PERFORM</b> key work is used to include subroutine in sapscript form...
But the processing is lttle bit different form the one we use in ABAP.
Here the paramters passed to form is stored in internal table of name-value table. there are two table one for inbound parameter and other for outbound parameters.
Check out the example below to see how this is used..
<b>Definition in the SAPscript form:</b>
/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
/: USING &PAGE&
/: USING &NEXTPAGE&
/: CHANGING &BARCODE&
/: ENDPERFORM
/ &BARCODE&
<b>Coding of the calling ABAP program:</b>
REPORT QCJPERFO.
FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
OUT_PAR STRUCTURE ITCSY.
DATA: PAGNUM LIKE SY-TABIX, "page number
NEXTPAGE LIKE SY-TABIX. "number of next page
READ TABLE IN_PAR WITH KEY PAGE.
CHECK SY-SUBRC = 0.
PAGNUM = IN_PAR-VALUE.
READ TABLE IN_PAR WITH KEY NEXTPAGE.
CHECK SY-SUBRC = 0.
NEXTPAGE = IN_PAR-VALUE.
READ TABLE OUT_PAR WITH KEY BARCODE.
CHECK SY-SUBRC = 0.
IF PAGNUM = 1.
OUT_PAR-VALUE = |. "First page
ELSE.
OUT_PAR-VALUE = ||. "Next page
ENDIF.
IF NEXTPAGE = 0.
OUT_PAR-VALUE+2 = L. "Flag: last page
ENDIF.
MODIFY OUT_PAR INDEX SY-TABIX.
ENDFORM.
Hope this is clear to understand...
Enjoy SAP.
Pankaj Singh. -
Need help in this sql query to use Case Statement
hi All,
I have the below query -
SELECT DISTINCT OFFC.PROV_ID
,OFFC.WK_DAY
,CASE
WHEN OFFC.WK_DAY ='MONDAY' THEN 1
WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
END AS DOW
,OFFC.OFFC_OPENG_TIME
,OFFC.OFFC_CLSNG_TIME
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID='0000600'
WITH UR;
this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
can somebody help me in achieving that.
thanks,
iamhereHi,
Welcome to the forum!
That's called a Pivot .
Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
SELECT OFFC.PROV_ID
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_OPENG_TIME END) AS mon_opn
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS mon_cls
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_OPENG_TIME END) AS tue_opn
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS tue_cls
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID = '0000600'
GROUP BY offc.prov_id
;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
Edited by: Frank Kulash on Jan 6, 2011 8:22 PM -
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. -
How to use collect statement for below
data : begin of itab,
n(3) type c,
n1 type n,
k(5) type c,
end of itab.
select n n1 from into itab table /zteest.
*internal table has
n n1 k
gar 100 uji
hae 90 iou
gar 90 uji
hae 87 iou
I want
gar 190
hae 177
How to use collect statement as n1 is n ..?
let me know..
Thankstry this..
DATA : BEGIN OF itab OCCURS 0,
n(3) TYPE c,
n1(3) TYPE p DECIMALS 2,
k(5) TYPE c,
END OF itab.
itab-n = 'gar'.
itab-n1 = 100.
itab-k = 'uji'.
COLLECT itab .CLEAR itab.
itab-n = 'hae'.
itab-n1 = 90.
itab-k = 'iou'.
COLLECT itab .CLEAR itab.
itab-n = 'gar'.
itab-n1 = 90.
itab-k = 'uji'.
COLLECT itab .CLEAR itab.
itab-n = 'hae'.
itab-n1 = 87.
itab-k = 'iou'.
COLLECT itab .CLEAR itab. -
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM
Maybe you are looking for
-
I can no longer send emails, but can receive them. Something about smtp?
Hi, I need help. I am overseas at my parents house and using their wireless internet and i went to go and send emails from my Mail application (using my .Me account) just like i have done plenty of times in the past and for some reason i can no longe
-
Cover Flow in Finder doesn't display Preview Annotations
When looking at PDFs using Cover Flow in Finder, the Preview Annotations aren't shown. Both Quick Look and Preview will show them.
-
How to import multiple folders?
When I want to import a folder with sub folders within it and I drag that into iTunes it does not import the subfolder structure. Is there a way of achieving this without having to import one folder at a time? Kevin
-
Report painter grr2- urgent!
Hi! I introduced in GRR2 a new line (new set of accounts) and I udated the formulas (the total where this new line should be included). But I dont understand why this new line is shown in red colour!!!!! (like the lines with totals). Please give me a
-
Hi, I am working in SAP Netweaver latest version. My requirement is to display a HTML page in the view.I have used iframe functionality.The file has been imported to MIME and in the source area ,i have given this file name. But the result is sho