Using Decode Or Case Statement / Any Method
Dear All,
In my table Fields are
EmpId
TranYear
TranMonth
ApprovedBy
ApprovedYear
ApprovedMonth
My Input parameters are
1. TranYear
2. TranMonth
3. Tag1
4. Tag2
My requirement is
Tag1 Input are 0,1,2
Tag2 Inputs are 0,1,2
If Tag1 is 0 then checking TranYear/TranMonth And
Tag2 Is 0 Then ApprovedBy Is Not Null only
Tag2 Is 1 Then ApprovedBy Is Null only
Tag2 Is 2 Then both(Approved/unApproved)
If Tag1 is 1 then checking ApprovedYear/ApprovedMonth And Tag2 Passing 0 Default
If Tag1 is 2 then checking TranYear/TranMonth Or ApprovedYear/ApprovedMonth And
Tag2 Is 0 Then ApprovedBy Is Not Null only
Tag2 Is 1 Then ApprovedBy Is Null only
Tag2 Is 2 Then both(Approved/unApproved)
Based upon the input details select details
dont quite understand your table structure requirement but it sounds like you want a conditional join.
looks like you are always joining on the tran year tran month but according to your 2 flags decides the rest of the join
I started something here where I am joining on the tran year / tran month then setting an indicator based on your flags
then just select the rows where this indicator is true.
anyway you can modify it to your needs
WITH t AS (SELECT 1 EmpId,
EXTRACT (YEAR FROM TO_DATE ('2010', 'YYYY')) TranYear,
EXTRACT (MONTH FROM TO_DATE ('Oct', 'Mon')) TranMon,
10 approved_by,
EXTRACT (YEAR FROM TO_DATE ('2010', 'YYYY')) ApprovedYear,
EXTRACT (MONTH FROM TO_DATE ('Nov', 'Mon')) ApprovedMon
FROM DUAL
UNION ALL
SELECT 2,
EXTRACT (YEAR FROM TO_DATE ('2009', 'YYYY')),
EXTRACT (MONTH FROM TO_DATE ('Jul', 'Mon')),
11,
EXTRACT (YEAR FROM TO_DATE ('2009', 'YYYY')),
EXTRACT (MONTH FROM TO_DATE ('Dec', 'Mon'))
FROM DUAL),
input AS (SELECT EXTRACT (YEAR FROM TO_DATE ('2010', 'YYYY')) TranYear,
EXTRACT (MONTH FROM TO_DATE ('Oct', 'Mon')) TranMon,
0 tag1,
0 tag2
FROM DUAL)
SELECT *
FROM (SELECT t.*,
tag1,
tag2,
CASE tag1 || '.' || tag2
WHEN '0.0'
THEN
CASE WHEN Approved_By IS NOT NULL THEN 1 ELSE 0 END -- if they are both 0 join on Tran Year, Tran Month and Approved by not null
WHEN '0.1'
THEN
CASE WHEN Approved_By IS NULL THEN 1 ELSE 0 END -- if they are 0,1 then Tran Year, Tran Month and Approved by is null
WHEN '0.2'
THEN
0 -- CASE --Then both(Approved/unApproved) i Don't know what this means
/* WHEN '1.0' then whatever
when '1.1' then whatever
when '1.2 then whatever
ELSE
0
END
ind
FROM t, input
WHERE t.TranYear = input.TranYear AND t.TranMon = input.TranMon)
WHERE ind = 1
Similar Messages
-
Hi,
I have query with a case statement as follows:
SELECT * FROM table
WHERE
CASE WHEN :variable like 'A' THEN column END is null
WHEN :variable like 'B' THEN column END is not null;
This works fine when returning "column is null" but not when "column is not null".
Can I use a CASE statement like this?
Thanks
LucyMy data is too complicated to show, but depending on the value of the bind variable in the statement I want to return all the rows in a query where the data in a particular column is either null or not null.For example, looking at the EMP table, if my bind variable is whether I want to show the top manager or not, if set to 'Yes' I would like to return all rows of the EMP table where mgr is null (i.e. the one row where ename is 'KING'), if it were set to 'No' I would like to return all the rows where mgr is not null (i.e. all the other rows). The difference with my query is that the column contains strings, not numerics.
I've used a CASE statement before where I equate the column to a particular value and that works fine, but I'm not sure how they deal with nulls. I've also tried DECODE and didn't get anywhere with that.
Thanks
Lucy -
How to use decode or case function in this?
Hi,
I want to implement this condition in a query without using any user defined functions
1.if (T_fees = 'ABC' then if (p_fees>0) then nvl(p_fees,0) else (p_fees + a_fees) else 0)
2. if(g_fees <> (if t_fees = 'ABC' then if (p_fees>0) then nvl(p_fees,0) else (p_fees)
else 0
Is it possible to use any nested 'CASE' statement ?
This is very urgent...
Regards,
ShilpaHi,
Is it possible to use any nested 'CASE' statement ?Yes it it possible.
"afiedt.buf" 7 lines, 89 characters
1 SELECT sysdate FROM DUAL
2 WHERE 1 = (CASE WHEN 1=1 AND 2=2 THEN
3 1
4 ELSE
5 2
6* END)
SQL>/
SYSDATE
07-AUG-06
1 row selected.
"afiedt.buf" 11 lines, 139 characters
1 SELECT sysdate FROM DUAL
2 WHERE 1 = (CASE WHEN 1=1 AND 2=2 THEN
3 CASE WHEN 3=3 AND 4=4 THEN
4 1
5 ELSE
6 0
7 END
8 ELSE
9 0
10* END)
SQL>/
SYSDATE
07-AUG-06
1 row selected.
You can implement your logic.
Regards -
Decode and case statement in the update..
Its is more to it, but I want to check with you guys, the experts on this, this look busy to me, it should be a more simplify way of doing it, do you think will work
The government decide to change the ethnic codes, and we have to come with certain rules to in our report, anyway, do you think this will work? again It is more to it I declare my variables, this is just one part of the precedure.
BEGIN
UTL_FILE.fclose_all;
v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'a');
UTL_FILE.put_line (v_file_handle,
CHR (10) || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
UTL_FILE.put_line (v_file_handle, 'Entering spbpers_update');
SELECT upd_spbpers_upd_cur IS
spriden_pidm,
szscapp_birth_state,
szscapp_birth_city,
DECODE(szscapp_hisp_or_latino_ind,Y,'2',N,'1'),
DECODE(szscapp_hisp_or_latino_options,XCM,'2',CUB,'2',MEX,'2',PRI,'2',XSM,'2',ESP,'2',XOH,'2'),
DECODE(szscapp_amer_indn_alaska_opt,XAN,'1','1',XCW,'1',XCH,'1',XCK,'1',XNV,'1',XSX,'1'),
DECODE(szscapp_amer_indn_alaska_other,XON,'1') (,IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'),
DECODE(szscapp_asian_options,IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'), ,
DECODE(szscapp_other_east_asia,(IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'),
DECODE(szscapp_other_indian_subcont,XIS,'1'),
DECODE(szscapp_other_southeast_asia,XSA,'1'),
DECODE(szscapp_blk_or_afr_amer_opt,XAA,'1',XAF,'1',XCB,'1',XOA,'1'),
DECODE(szscapp_blk_or_afr_amer_other,XOA,'1'),
DECODE(szscapp_natve_hawaian_options,GUM,'1',XHI,'1',ASM,'1',XOP,'1'),
DECODE(szscapp_hawaiian_other,XOP,'1'),
DECODE(szscapp_white_options,XEU,'1',XME,'1',XOW,'1'),
DECODE(szscapp_white_other(XOW,'1')
FROM
saturn_midd.szscapp
WHERE
spriden_id = szscapp_id
AND spriden_ntyp_code = 'CAPL'
IF upd_spbpers_upd_cur%ISOPEN
THEN
CLOSE upd_spbpers_upd_cur;
END IF;
OPEN upd_spbpers_upd_cur;
LOOP
FETCH upd_spbpers_upd_cur
INTO v_pidm,v_birth_state,v_birth_city,v_latino_ind,v_latino_options,
v_indn_alaska_opt,v_indn_alaska_other,v_asian_options,
v_other_east_asia,v_other_indian_subcont,v_other_southeast_asia,
v_blk_or_afr_amer_opt,v_blk_or_afr_amer_other,v_natve_hawaian_options,
v_hawaiian_other,v_white_options,v_white_other;
EXIT WHEN upd_spbpers_upd_cur%NOTFOUND;
IF upd_spbpers_upd_cur%FOUND
UPDATE saturn.spbpers
set SPBPERS_ETHN_CODE = CASE
WHEN v_latino_ind IS NOT NULL THEN (spbpers_ethn_code = v_latino_ind,spbpers_activity_date = sysdate)
WHEN v_latino_options IS NOT NULL THEN (spbpers_ethn_code = v_latino_options,spbpers_activity_date = sysdate)
WHEN v_indn_alaska_opt IS NOT NULL THEN (spbpers_ethn_code = v_indn_alaska_opt,spbpers_activity_date = sysdate)
WHEN v_indn_alaska_other IS NOT NULL THEN (spbpers_ethn_code = v_indn_alaska_other,spbpers_activity_date = sysdate)
WHEN v_asian_options IS NOT NULL THEN (spbpers_ethn_code = v_asian_options,spbpers_activity_date = sysdate)
WHEN v_other_east_asia IS NOT NULL THEN (spbpers_ethn_code = v_other_east_asia,spbpers_activity_date = sysdate)
WHEN v_other_indian_subcont IS NOT NULL THEN (spbpers_ethn_code = v_other_indian_subcont,spbpers_activity_date = sysdate)
WHEN v_other_southeast_asia IS NOT NULL THEN (spbpers_ethn_code = v_other_southeast_asia,spbpers_activity_date = sysdate)
WHEN v_blk_or_afr_amer_opt IS NOT NULL THEN (spbpers_ethn_code = v_blk_or_afr_amer_opt,spbpers_activity_date = sysdate)
WHEN v_blk_or_afr_amer_other IS NOT NULL THEN (spbpers_ethn_code = v_blk_or_afr_amer_other,spbpers_activity_date = sysdate)
WHEN v_natve_hawaian_options IS NOT NULL THEN (spbpers_ethn_code = v_natve_hawaian_options,spbpers_activity_date = sysdate)
WHEN v_hawaiian_other IS NOT NULL THEN (spbpers_ethn_code = v_hawaiian_other,spbpers_activity_date = sysdate)
WHEN v_white_options IS NOT NULL THEN (spbpers_ethn_code = v_white_options,spbpers_activity_date = sysdate)
WHEN v_white_other IS NOT NULL THEN (spbpers_ethn_code = v_white_other,spbpers_activity_date = sysdate)
WHEN v_birth_state IS NOT NULL THEN (spbpers_stat_code_birth = v_birth_state,spbpers_activity_date = sysdate)
WHEN v_birth_city IS NOT NULL THEN (spbpers_city_birth = v_birth_city,spbpers_activity_date = sysdate)
WHERE spbpers_pidm = v_pidm;
END
END IF;
END LOOP;Did the procedure compile ?
Doesn't look like a right Decode syntax.
DECODE (col1,'VAL1','This','VAL2','That','ElseThis')
means
--Psuedocode
IF col1 = 'VAL1' THEN 'This'
IF col1 = 'VAL2' THEN 'That'
ELSE 'ElseThis'You can use CASE statement Instead of DECODE
CASE
when szscapp_amer_indn_alaska_other
in ('XON','IND','JPN','KOR','PAK' ..... ) THEN '1'
when szscapp_hisp_or_latino_options
in ('XCM','CUB','MEX','PRI','XSM','ESP','XOH' ...) THEN '2'
END SS -
Query to find out sum by using decode or case
Hi, I have data like below and required an output as given below, could you please help me to get the same by using decode / case .....Thanks for your help
INSNAME INSID STATUS
AAA 1000 Scheduled
AAA 1000 Processing
BBB 1001 Inspector
BBB 1001 Scheduled
BBB 1001 Processing
BBB 1001 Inspector
CCC 1002 Scheduled
CCC 1002 Processing
CCC 1002 Inspector
CCC 1002 Scheduled
CCC 1002 Processing
CCC 1002 Inspector
Required Output...
INSNAME INSID sum_of_scheduled sum_of_Processing sum_of_Inspector
AAA 1000 1 1 0
BBB 1001 1 1 2
CCC 1002 2 2 2And if you want it with CASE statement:
WITH test_table AS
SELECT 'AAA' insname, 1000 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'AAA' insname, 1000 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Inspector' status FROM DUAL
SELECT insname
,insid
,SUM(CASE WHEN status = 'Scheduled'
THEN 1
ELSE 0
END
) sum_of_scheduled
,SUM(CASE WHEN status = 'Processing'
THEN 1
ELSE 0
END
) sum_of_processing
,SUM(CASE WHEN status = 'Inspector'
THEN 1
ELSE 0
END
) sum_of_inspector
FROM test_table
GROUP BY insname
,insid;
Regards
Arun -
How to use REGEXP for case statement
Hello everyone, I'm very new here and am struggling with a using REGEXP in a case statement, OK I am using the REGEXP to find all strings that match a specific format for a particular brand of product, for example serial numbers, and I need to be able to say something like [case when(xx.brandid) = '123' then if xx.serialnumber REGEXP_LIKE(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then 'TRUE' else 'FALSE' end "TRUE/FALSE".]
Help would be greatly appreciated with this as I feel like I'm going backwards trying to figure this out
Thanks in advance for any assistance.Like this?
case
when xx.brandid = '123' and
regexp_like(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then
'TRUE'
else
'FALSE'
end -
Grouping using report query / Case statement in toplink
I have following tables
1. Student with columns id, gender
2. Subject_Score with columns id, student_id, subject_id, score
To get scores grouped by subject, I am doing
ExpressionBuilder subjScoreBuilder = new ExpressionBuilder();
ReportQuery query = new ReportQuery(SubjectScore.class);
query.addAverage("average-score",subjScoreBuilder.get("score"));
query.addGrouping(subjScoreBuilder.get("subjectId"));
Vector responses = (Vector) serverSession.executeQuery(query);
Float score = (Float) queryResult.get("average-score");
This works fine. It gives avg score per each subject
Now i want both in one query
A) avg score per subject
B) avg score per subject per gender
I want to achive this in one query
I am doing like:
ExpressionBuilder subjScoreBuilder =new ExpressionBuilder(SubjectScore.class);
ExpressionBuilder studentExpBuilder = new ExpressionBuilder(Student.class);
Expression expression = subjScoreBuilder.get("studentid").equal(studentExpBuilder.get("id")));
ReportQuery query = new ReportQuery(SubjectScore.class, expression);
query.addAverage("average-score", subjScoreBuilder.get("score"));
query.addGrouping( subjScoreBuilder.get("subjectId"));
query.addGrouping( studentExpBuilder.get("gender"));
This gives me avg scor per each subject per gender. i.e.
it applies grouping on both subjectId & gender.
This is fine.
But I also want avg score per each subject (group on subject only) in same query.
1. How can we achive it?
2. is there something like Case statement in toplink?
Thanks a lot for any help.I believe in SQL you would need two queries to do this directly, so you will need to issue two queries.
You could select the Count and Avg, this would give you all the data need to compute the Avg yourself.
i.e.
(count(male) * avg(male) + count(female) * avg(female)) / (count(male) + count(female)) -
I am having issue in group by using decode and case in pl/sql
my query is some thing like this but having more column in select. when i am firing this query it is giving result but that is not proper
my problem is , like if there are 3 more values for uh.sflowtype (0,1,2) then group by is not working for them and those are coming in different row , i need them to be combined
query is :
select substr(uh.sstartdatetime,1,8) DateTime,
( case
when uh.sflowtype=7 then 'sms'
when uh.sflowtype=9 then 'mms'
when uh.sflowtype=10 then 'gprs'
else 'voice'
end )
as flowtype from e_vpn_usagehistory uh where 1=1 and uh.nspid='1' AND ((substr(uh.sstartdatetime,1,8) >= 20130507 )
AND (substr(uh.sstartdatetime,1,8) <= 20130606)) GROUP BY substr(uh.sstartdatetime,1,8),uh.sflowtype
order by substr(uh.sstartdatetime,1,8) DESC
result :
DATETIME FLOWTYPE
20130507 voice
20130507 voice
20130507 voice
20130507 sms
20130507 mms
but i need
20130507 voice
20130507 sms
20130507 mms
so what should i do?
please suggest me996962 wrote:
my query is some thing like this but having more column in select. when i am firing this query it is giving result but that is not proper
my problem is , like if there are 3 more values for uh.sflowtype (0,1,2) then group by is not working for them and those are coming in different row , i need them to be combined
query is :
select substr(uh.sstartdatetime,1,8) DateTime,
( case
when uh.sflowtype=7 then 'sms'
when uh.sflowtype=9 then 'mms'
when uh.sflowtype=10 then 'gprs'
else 'voice'
end )
as flowtype from e_vpn_usagehistory uh where 1=1 and uh.nspid='1' AND ((substr(uh.sstartdatetime,1,8) >= 20130507 )
AND (substr(uh.sstartdatetime,1,8) <= 20130606)) GROUP BY substr(uh.sstartdatetime,1,8),uh.sflowtype
order by substr(uh.sstartdatetime,1,8) DESC
result :
DATETIME FLOWTYPE
20130507 voice
20130507 voice
20130507 voice
20130507 sms
20130507 mms
but i need
20130507 voice
20130507 sms
20130507 mms
so what should i do?
please suggest meWell, you are grouping by substr(uh.sstartdatetime,1,8),uh.sflowtype
so different values of sflowtype that aren't 7,9 or 10 will be grouped separately.
You therefore need to group by your case statement instead of just the sflowtype.
The most worrying thing though is that you have sstartdatetime that appears to be a varchar2 and not a date.
If it is a date, you are applying a substr (which applies to strings) to a date. you then compare the result
of the substr to a number.
This is a recipe for future problems: sort it out using the correct conversion functions with format masks.
Edited by: Paul Horth on May 14, 2013 1:25 PM -
What will be good for proformance wise:
Decode or Case in a sql statement.?????See the following link for Tom Kyte's opinion (point #4 in his first answer):
http://asktom.oracle.com/pls/ask/f?p=4950:8:16717708356827415201::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:1243867216406 -
To use Boolean function in DECODE or CASE statement
Hi all
I have a scenario where i need to use a boolean function inside DECODE statement. When i tried this way iam getting "ORA-06553: PLS-382: expression is of wrong type".
I doubt whether i can use boolean function inside DECODE or not?
My query will be like this:
select decode(my_fuction( ),'TRUE',1,'FALSE',0) from dual;
Any help is highly appreciated.
Thanks
SriramOverloaded functions must differ by more than their
return type . At the time that the overloaded
function is called, the compiler doesn't know what type
of data that function will return. The compiler cannot,
therefore, determine which version of the function to
use if all the parameters are the same. -
Pivoting using Model Clause Vs pivoting using Aggregate Fun(Case) statement
Hi,
I just wanted to know which option is better for pivoting the data if the data is like:
Grp1 Grp2 Day_week Sales
1 1 Sun 200
1 1 Mon 100
1 2 Sun 1000
and so on...
The output should be:
Grp1 Grp2 Sun Mon ......
1 1 200 100.....
1 2 1000 NULL....
I have tested the same using sum(decode...) method and also model clause:
select grp1, grp2, sum(decode(day_week,'SUN',sales)) SUNDAY , sum(decode(day_week,'MON',sales)) MONDAY from pivot
group by grp1, grp2
order by grp1, grp2
select grp1, grp2, sun , mon, tue, wed, thr, fri, sat
from pivot
model -- UNIQUE SINGLE REFERENCE
return updated rows
partition by (grp1, grp2)
dimension by ( day_week)
measures( result, 0 mon, 0 tue, 0 wed, 0 thr,0 fri, 0 sat, 0 sun)
RULES upsert
mon[0]= sales['MON'],
tue[0]= sales['TUE'],
wed[0]= sales['WED'],
thr[0]= sales['THR'],
fri[0]= sales['FRI'],
sat[0]= sales['SAT'],
sun[0]= sales['SUN']
) order by grp1, grp2
There are 4K records in the table. The first query is taking app (.125 seconds) and the second query (.230 seconds).
Pls tell how the model clause can give better performance and I want to use it for pivoting in all my APIs.
Regards
Rajiv> I read somewhere while searching on net.
And now you can't find it anymore? I wouldn't believe anything you read somewhere while searching on net, unless it has some kind of proof attached.
> You pls tell is it so or it depends upon volume of data.
Also i tested on some data and reults were better in
case of using normal startegy rather than model.(case
provided above).
So you have tested it yourself already. The model clause is great in a few cases (string aggregation, calculating values based on calculated values), but this doesn't seem to be one of them. On 11g you might want to consider the PIVOT operator.
Regards,
Rob. -
Using ISNULL in CASE statement
Hi,
I need to write a query that will gimme the resultsets based on a data comparison with some values, Those values that are null in the result set needs to be replaced with an empty string which can be obtained using ISNULL function. My question here is,
how to incorporate this in a SELECT statement that has CASE expression. I coded some thing like this but the result set for the column is returning zero instead of an empty string. The data type for this column ABC is varchar(10)
SELECT top 20
ABC
,CASE
WHEN ABC IN (8,9,10,13,14,15,16,17,19,20,21) THEN 10
WHEN ABC IN (31,32,33) THEN 30
WHEN ABC IN (53,52,54,55) THEN 50
WHEN ABC IN (61,62) THEN 60
WHEN (ABC IS NULL AND DEF IS NOT NULL) THEN 99
else ISNULL(ABC,'')
END
FROM XYZ
Any help is appreciated
Many Thanks,
BhanuSELECT top 20
ABC
,CASE
WHEN ABC IN (8,9,10,13,14,15,16,17,19,20,21) THEN '10'
WHEN ABC IN (31,32,33) THEN '30'
WHEN ABC IN (53,52,54,55) THEN '50'
WHEN ABC IN (61,62) THEN '60'
WHEN (ABC IS NULL AND DEF IS NOT NULL) THEN '99'
else ISNULL(ABC,'')
END
FROM XYZ -
More effecient way of using Decode and CASE
Is it possible to use both case and decode together? I feel I have too many decode and I am not sure how to write this in a more efficient way.
I would really appreciate any help.
Thank you so much in advance!!!
SELECT Person_ID,Work_ID,
CASE WHEN NBR = 1 THEN
MIN(DECODE(NBR, 1, field1)) aug_one_field1;
MIN(DECODE(NBR, 1, field2)) aug_one_field2;
MIN(DECODE(NBR, 1, field3)) aug_one_field3;
MIN(DECODE(NBR, 1, field4)) aug_one_field4;
MIN(DECODE(NBR, 1, field5)) aug_one_field5;
MIN(DECODE(NBR, 1, field6)) aug_one_field6;
CASE WHEN NBR = 2 THEN
MIN(DECODE(NBR, 2, field1)) aug_two_field1;
MIN(DECODE(NBR, 2, field2)) aug_two_field2;
MIN(DECODE(NBR, 2, field3)) aug_two_field3;
MIN(DECODE(NBR, 2, field4)) aug_two_field4;
MIN(DECODE(NBR, 2, field5)) aug_two_field5;
MIN(DECODE(NBR, 2, field6)) aug_two_field6;
CASE WHEN NBR = 3 THEN
MIN(DECODE(NBR, 3, field1)) aug_three_field1;
MIN(DECODE(NBR, 3, field2)) aug_three_field2;
MIN(DECODE(NBR, 3, field3)) aug_three_field3;
MIN(DECODE(NBR, 3, field4)) aug_three_field4;
MIN(DECODE(NBR, 3, field5)) aug_three_field5;
MIN(DECODE(NBR, 3, field6)) aug_three_field6;
CASE WHEN NBR = 4 THEN
MIN(DECODE(NBR, 4, field1)) aug_four_field1;
MIN(DECODE(NBR, 4, field2)) aug_four_field2;
MIN(DECODE(NBR, 4, field3)) aug_four_field3;
MIN(DECODE(NBR, 4, field4)) aug_four_field4;
MIN(DECODE(NBR, 4, field5)) aug_four_field5;
MIN(DECODE(NBR, 4, field6)) aug_four_field6;
END
FROM (SELECT Person_ID,Work_ID, NBR
fiel1, field2, field3,field4,field5, field6,
FROM field_rep
GROUP BY Person_ID,Work_IDThanks alot John and Frank.
John to answer your question, I just felt the 24 or more decode will slow down the systems performance, hence I was trying to find a better way to do it.
Frank
This is a sample data but I want it pivoted hence the reason for using the decode. I have oracle 10g. These are sample data
Person_id work_id NBR field1 field2 field3 field4 field5 field6
1 ao334 1 1/2/2009 1/9/2010 block_A HH 55667 1
1 ao334 2 5/2/2011 9/9/2013 block_Z HL 11111 3
1 ao334 2 1/2/2009 1/9/2010 block_A HH 22222 1
1 ao334 4 1/2/2009 1/9/2010 block_A HH zzzzz 7
1 z5521 1 10/5/2006 12/31/2012 block_C SS 33322 1
1 z5521 2 1/2/2009 1/9/2010 block_C SS 21550 1
1 z5521 3 1/2/2009 1/9/2010 block_R SS 10000 1
1 z5521 4 1/2/2009 1/9/2010 block_D SS 99100 5
1 z5521 5 1/2/2009 1/9/2010 block_P SS 88860 1
1 z5521 6 1/2/2009 1/9/2010 block_G SS 99660 8
1 ob114 1 1/2/2009 1/9/2010 block_A HH 52333 1
1 ob114 2 1/2/2009 1/9/2010 block_A HH 88888 1Output will look like this
Person_id work_id aug_one_field1 aug_one_field2 aug_one_field3 aug_one_field4 aug_one_field5 aug_one_field6 aug_two_field1 aug_two_field2 aug_two_field3 aug_two_field4 aug_two_field5 aug_two_field6
1 ao334 1/2/2009 1/9/2010 block_A HH 55667 1 5/2/2011 9/9/2013 block_Z HL 11111 3 -
How do I use switch and case statements to fill more than one other field?
Hi all,
I'm new to the community.
I'm trying to make an existing form more user friendly for my coworkers. I want to use a switch and case approach in a drop-down list field so that the selection fills two seperate other fields with different info related to the selection.
I can already do this with one field, but if I add a second target field under an existing case the text doesn't appear there when I make the selection from the dropdown.
Basically, I'm asking if I can do this:
switch
(sNewSel){
case "1": // Selection 1 Row2.Field1
= "text for field 1";
Row1.Field2 = "text for field 2";
break;
etc.
It works if the "row1.field2" option isn't there, but not when it is present.
Any takers?I'm not sure if I will be able to send you the form. There may be too much to redact.
Would this last bit of code in the cell affect anything?
if
(bEnableTextField)
{Row2.Field1.access
= "open"; // enable field
Row2.Field1.caption.font.fill.color.value= "0,0,0"; // set caption to black
That is, do I also need to repeat the same thing for the second target cell (Row1.Field2)?
What would be possible hang ups that would prevent it from working correctly?
Dave
By the way, I'm not sure if my other attachment posted. I am trying again. -
Hi All,
I have an issue cannot resolve myself, need help.
DA1> desc test_case
Name Null? Type
ID NUMBER
ID_DESC VARCHAR2(30)
CUR_AMT NUMBER
PRV_AMT NUMBER
YEAR VARCHAR2(4)
LOAN_AMT NUMBER
DA1> select * from test_case;
ID ID_DESC CUR_AMT PRV_AMT YEAR LOAN_AMT
10 DAILY 2000 2050 2008 4050
20 Weekly 11000 12000 2008 23000
30 Bi-Weekly 23000 24000 2008 47000
40 Monthly 47000 45000 2008 92000
50 Yearly 500000 490000 2008 990000
We have now decided that for ID 40 and 50 the following is the criteria.
1. the ID_DESC will be concatenated ' (N/A)'
2. the LOAN_AMT will be shown same as that of Bi-Weekly.
Example:
ID ID_DESC CUR_AMT PRV_AMT YEAR LOAN_AMT
40 Monthly (N/A) 47000 45000 2008 47000
50 Yearly (N/A) 500000 490000 2008 47000
I was able to do the follwoing:
DA1> select id,
2 decode(id, 40, id_desc || ' (N/A)',
3 50, id_desc || ' (N/A)',
4 id_desc) id_desc,
5 cur_amt,
6 prv_amt,
7 year,
8 loan_amt
9 from test_case;
ID ID_DESC CUR_AMT PRV_AMT YEAR LOAN_AMT
10 DAILY 2000 2050 2008 4050
20 Weekly 11000 12000 2008 23000
30 Bi-Weekly 23000 24000 2008 47000
40 Monthly (N/A) 47000 45000 2008 92000
50 Yearly (N/A) 500000 490000 2008 990000
I am unable to figure out how to assign the loan_amt for ID 30 to ID 40 and 50.
this query is used in a report.
Note: the actual table and its values are different.
thanks for all the help;
HabeebThanks to all,
Finally I figured it...
Below is the query...
DA1> select id,
2 decode(id, 40, id_desc || ' (N/A)',
3 50, id_desc || ' (N/A)',
4 id_desc) id_desc,
5 cur_amt,
6 prv_amt,
7 year,
8 decode(id, 40, (select loan_amt
9 from test_case
10 where id = 30),
11 50, (select loan_amt
12 from test_case
13 where id = 30),
14 loan_amt) loan_amt
15 from test_case;
ID ID_DESC CUR_AMT PRV_AMT YEAR LOAN_AMT
10 DAILY 2000 2050 2008 4050
20 Weekly 11000 12000 2008 23000
30 Bi-Weekly 23000 24000 2008 47000
40 Monthly (N/A) 47000 45000 2008 47000
50 Yearly (N/A) 500000 490000 2008 47000
habeeb
Maybe you are looking for
-
Dropped internet connection in Vista 32
Hello, I'm running a MacPro. While running in Vista 32 under boot camp my internet connection drops out. When I first boot up, My internet connection is perfectly fine. However as time goes on the connection drops and takes a re-boot to get it workin
-
Startup problem - no startup options
I've been having numerous problems with my X61 7675-CTO with Win Vista Business and most of them are due to Lenovo's system updates. But this one is a "residue" from when I had my computer sent in for service. Ever since, upon startup I hear three be
-
Loading master/transaction data from BI to NW BPC
hi what is best way of loading master & transaction data from BI to BPC? I know around 6 options for loading master data and 5 options for loading transactional data from BI to BPC . What is easiest and recommended method? what is typical method foll
-
Mate Framework compiler errors
I can get the Mate Framework to compile under the Flex 4 beta 1 SDK with minor changes. However if I use the latest nightly Flex 4 SDK (full Adobe version), I get the following compiler errors that I can't seem to figure out why I'm getting: - 1017:
-
Burning a website to a CD?
Hi, I need to burn my website I created in Dreamweaver CS4 to a CD. How do I do this? Also, do I burn all the files within my created site (that is everything in the Files panel)? I know this is probably really easy to do but I'm just new to creating