Nested CASE Statements in my SELECT of Query not calculating correctly
Hi - Am doing simple query to calculate statistics on students per course, the WHERE includes a parameter for Academic Year, so need If Academic Year = x then calculate age in the 1st Sept of that Year, then count number of 19Yrs&Over. Have included my successful lines for sum of other data, in my CASE the calculations are not distinguishing whether age is over or under 19 just counting all. Presume is problem with Date calculation or CASE?? Runs without error..I'm guessing I can nest a CASE?!
Many thanks!
SELECT ......
various fields bought through then
count(p.PERSON_CODE) All_Enrolments,
sum(DECODE(ru.FES_PROGRESS_CODE,'ACT',1,0)) Active,
sum(DECODE(ru.FES_PROGRESS_CODE,'WNS',1,0)) NonStarter,
sum(DECODE(ru.FES_PROGRESS_CODE,'WTH',1,0)) Withdrawn,
sum(DECODE(ru.FES_PROGRESS_CODE,'TRN',1,0)) Transfers,
sum(DECODE(la.completion,'2',1,0)) Completed,
sum(DECODE(la.outcome,'1',1,0)) Achieved,
sum(DECODE(p.sex,'F','1','0')) Female,
sum(DECODE(p.sex,'M','1','0')) Male,
SUM(
CASE
WHEN uio.CALOCC_OCCURRENCE_CODE='04'
THEN
CASE
WHEN ((to_date('01-08-2004','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
THEN '0'
ELSE '1'
END
WHEN uio.CALOCC_OCCURRENCE_CODE='05'
THEN
CASE
WHEN ((to_date('01-08-2005','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
THEN '0'
ELSE '1'
END
WHEN uio.CALOCC_OCCURRENCE_CODE='03'
THEN
CASE
WHEN ((to_date('01-08-2003','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
THEN '0'
ELSE '1'
END
ELSE '0'
END ) Over19sInc19
FROM .......
you can use this formula to check on the age:
TRUNC(MONTHS_BETWEEN(to_date('01-08-2004','dd-mm-yyyy'),to_date(p.date_of_birth,'dd-mm-yyyy'))/12)hope this helps.
Similar Messages
-
Having Trouble with nested Case Statements
Hi Folks,
I'm having trouble getting my head round nested case statements. For the life of me I cannot see what I'm missing here (unless my approach is all wrong).
Any help much appreciated.
Script:
set serveroutput on format wrapped
set feedback off
set linesize 150
DECLARE
/* Set supported version here */
ora_version VARCHAR2(4);
unsupp_version EXCEPTION;
/* Archive Log Info */
db_log_mode VARCHAR2(12);
BEGIN
SELECT SUBSTR(VERSION, 1, 4)
INTO ora_version
FROM v$instance;
SELECT log_mode
INTO db_log_mode
FROM v$database;
CASE
WHEN ora_version = '10.2' THEN
DECLARE
TYPE t_db IS RECORD(
dflsh VARCHAR2(3),
dcscn NUMBER);
v_db t_db;
BEGIN
CASE
WHEN db_log_mode = 'ARCHIVELOG' THEN
EXECUTE IMMEDIATE 'SELECT INITCAP(flashback_on), current_scn FROM v$database'
INTO v_db;
DBMS_OUTPUT.PUT_LINE(' Flashback On : ' || v_db.dflsh);
DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
END;
ELSE
DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
END CASE;
END;
WHEN ora_version = '9.2' THEN
DECLARE
TYPE t_db IS RECORD(
dcscn NUMBER);
v_db t_db;
BEGIN
CASE
WHEN db_log_mode = 'ARCHIVELOG' THEN
EXECUTE IMMEDIATE 'SELECT current_scn FROM v$database'
INTO v_db;
DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
END;
ELSE
DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
END CASE;
END;
ELSE
RAISE unsupp_version;
END CASE;
EXCEPTION
WHEN unsupp_version THEN
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE(' Unsupported Version '||ora_version||' !');
DBMS_OUTPUT.PUT_LINE('');
END;
set linesize 80
set feedback on
set serveroutput off
Gives errors:
END;
ERROR at line 31:
ORA-06550: line 31, column 7:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
case
ORA-06550: line 37, column 1:
PLS-00103: Encountered the symbol "WHEN"
ORA-06550: line 50, column 28:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
case
Edited by: milkyjoe on 28-Apr-2010 05:38Hi,
Never write, much less post, unformatted code.
Indent the code to show the extent of multi-line structures like BEGIN and CASE.
For example:
DECLARE
/* Set supported version here */
ora_version VARCHAR2 (4);
unsupp_version EXCEPTION;
/* Archive Log Info */
db_log_mode VARCHAR2 (12);
BEGIN
SELECT SUBSTR(VERSION, 1, 4)
INTO ora_version
FROM v$instance;
SELECT log_mode
INTO db_log_mode
FROM v$database;
CASE
WHEN ora_version = '10.2' THEN
DECLARE
TYPE t_db IS RECORD(
dflsh VARCHAR2(3),
dcscn NUMBER);
v_db t_db;
BEGIN
CASE
WHEN db_log_mode = 'ARCHIVELOG' THEN
EXECUTE IMMEDIATE 'SELECT INITCAP(flashback_on), current_scn FROM v$database'
INTO v_db;
DBMS_OUTPUT.PUT_LINE(' Flashback On : ' || v_db.dflsh);
DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
END;
...The code above is what you posted, with some whitespace added.
The error is much clearer; the last CASE statement concludes with END, but CASE blocks always have to conclude with END CASE .
Why are you using a nested BEGIN block in the code above? Are you plannning to add an EXCEPTION handler later?
When posting formatted text on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Sql 2008 nested case statement
I have a question about understanding nested case statements in sql server 2008:
The sql looks like the folloiwng:
select numberofcases
from inventory
where inventory_cnt > 1000
(when select top 1
from inventory
where inventory_cnt > 750
then numberofcases = 750 * 30
when select top 2
from inventory
where inventory_cnt > 975
then numberofcases = 975 * 35
when select top 3
from inventory
where inventory_cnt > 1025
then numberofcases = 1025 / 10
when select top 4
from inventory
where inventory_cnt > 1050
then numberofcases = 1050 / 5) c * 2
as casesused, select CustomerNumber from inventory
I would like you to explain the following:
1. There are 4 when statements. Will the logic hit each when statemnet or will the logic
stop once the first when statement is true?
2. Would you explain what the c* 2 means from the school listed above?Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
SELECT CASE
WHEN Inventory_cnt > 1050 THEN 1050 / 5
WHEN Inventory_cnt > 1025 THEN 1025 / 10
WHEN Inventory_cnt > 750 THEN 750 * 30
WHEN Inventory_cnt > 975 THEN 975 * 35
ELSE NULL END AS cases_used
FROM Inventory;
I would like you to explain the following:
>> 1. There are 4 when statements. Will the logic hit each when statement or will the logic stop once the first when statement is true? <<
This code is garbage, not SQL. CASE is an expression, not a statement. Expressions return a scalar value. Your are trying to do control flow! And the answer is that a CASE works this way
1) look at the THEN clauses and determine the data type to use
2) test each WHEN clause and execute the first one that tests TRUE in left to right order.
>> 2. Would you explain what the c* 2 means from the school listed above? <<
Syntax error and more garbage code.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to create nested CASE statements in PL/SQL
Can anyone please tell how to create Nested CASE statements in PL/SQL with proper syntax?
It would be better if you can help with an example.
Thank you!Something like this:
SQL> set serveroutput on
SQL> declare
2 v1 number := 2;
3 v2 varchar2(1) := 'C';
4 begin
5 case v1
6 when 1 then dbms_output.put_line('First');
7 when 2 then begin
8 case v2
9 when 'A' then dbms_output.put_line('Found A');
10 when 'B' then dbms_output.put_line('Found B');
11 when 'C' then dbms_output.put_line('Found C');
12 else dbms_output.put_line('NONE');
13 end case;
14 end;
15 else dbms_output.put_line('Else');
16 end case;
17 end;
18 /
Found C
PL/SQL procedure successfully completed
SQL> If you have further doubts regarding syntax you can read the docs on the Case statement here:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/case_statement.htm -
Hello,
I need help implementing multiple Case Statements in a select statement. I can not get this to work in one statement.
Select Statement
select distinct
allt.fk_jobcode_id as Job_Code,
allt.fk_jobcode_descr as Classification,
sum(allt.number_of_positions) as Number_Allotted,
sum(number_of_positions) as Sum_Number_Allotted,
dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
THEN div.division_name
END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,
allt.fund_type as Fund
from tbl_allotment allt, tbl_department dept, tbl_division div
where isdeleted <> 'Y'
and ALLT.FK_DEPARTMENT_ID = dept.department_id
and ALLT.FK_DIVISION_ID = div.division_id
group by fk_jobcode_id, fk_jobcode_descr, fund_type, department_name, division_name
HAVING (count(fk_jobcode_descr ) = 1)
order by Classification asc, Department_Division asc1st CASE Statement combines the Department_Name and Division_Name values but does not display the Division_Name if the value is 'N/A'.
dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
THEN div.division_name
END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,value: Council Administrator's Office/Administration
value: Council Administrator's Office/N/A will display as Council Administrator's Office
I need to extend this now by using this CASE Statement, which displays the text 'Public Works' if the Department_Id = 00072.
(CASE dept.department_id
When '00072' then 'Public Works'
Else dept.Department_Name
End) as Department_Name, incorrect: Road Rehab Program/GLP Transportation Program Admin
Should populate as: Public Works/GLP Transportation Program Admin
select distinct
allt.fk_jobcode_id as Job_Code,
allt.fk_jobcode_descr as Classification,
sum(allt.number_of_positions) as Number_Allotted,
sum(number_of_positions) as Sum_Number_Allotted,
dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
THEN div.division_name
END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,
(CASE dept.department_id
When '00072' then 'Public Works'
ELSE dept.Department_Name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
THEN div.division_name
END),'/'||DIV.DIVISION_NAME||'',null)
END) as Department_Name1,
allt.fund_type as Fund
from tbl_allotment allt, tbl_department dept, tbl_division div
where isdeleted <> 'Y'
and ALLT.FK_DEPARTMENT_ID = dept.department_id
and ALLT.FK_DIVISION_ID = div.division_id
group by fk_jobcode_id, fk_jobcode_descr, fund_type, department_name, division_name, department_id
HAVING (count(fk_jobcode_descr ) = 1)
order by Classification asc, Department_Division ascbut once I modify the select statement I am only getting value 'Public Works' for Department_Division value. Does not populate the Division_Name data. Does anyone know how to combine these CASE Statements? Thanks for reading this Thread also.Hi,
I think you want something like this:
SELECT ...
, CASE
WHEN department_id = '00072'
THEN 'Public Works'
ELSE dept.department_name
END
||
CASE
WHEN div.division_name != 'N/A'
THEN '/' || div.division_name
END AS department_name1
...Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using. -
SQL query not calculating
gross_amount is giving the value of extended_amount and the gross_price_rc is giving the value of unit_selling_price
select customer_trx_line_id,
( extended_amount / 1- (decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) GROSS_AMOUNT,
( unit_selling_price /1-(decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) gross_price_rc
from ra_customer_trx_lines_all
where attribute6 is not null or attribute7 is not null or attribute8 is not null or attribute9 is not null
whats the isuue here??
Thanksdecode(attribute7,null,0)Looking at it again, this always returns 0 or NULL, so it not really surprising
DECODE
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions040.htm#i1017437
CASE
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions004.htm#i1033392 -
T-sql case statement in a select
When I execute the following t-sql 2012 statement, the "NO Prod' value is not
being displayed from the sql listed below:
SELECT DISTINCT
IsNull(cs.TYPE,'') as type,
CASE IsNull(Course.TYPE,'')
WHEN 'AP' then 'AP Prod'
WHEN 'IB' then 'IB Prod'
WHEN 'HR' then 'HR Prod'
WHEN '' then 'NO Prod'
END AS label
FROM CustSection cs
INNER JOIN dbo.Person p on P.personID = cs.personID
Left join customCustomer cs564 on cs564.personID = p.personID and
cs564.attributeID ='564'
where ( cs.type is null and cs564.attributeID = null)
or
(cs.type IN ('HR','AP') OR
(cs.type='IB' AND SUBSTRING(cs.code,1,1)='3'))
ORDER BY label
What I want is for 'NO Prod' to be displayed when
cs.type is null and cs564.attributeId is null.
Thus can you tell me how to fix query above so the 'NO Prod' value is displayed in the
select statement listed above?There is no CASE statement in SQL; we have a CASE expression. We do not use the old 1970's Sybase*- ISNULL(); we have COALESCE().
There is no such thing as a magic generic “type” in RDBMS. There is no such thing as a generic “code” in RDBMS. They have to to be “<something in particular>_type” and “<something in particular>_code” in a valid data model. How about blood_type
and postal_code??
There is no such thing as a generic “person” table in RDBMS. First of all, do you really have only one person, as you said?? But the important point is that these persons play a role in the data model – customers, students, etc. You are doing the wrong thing
and doing it badly. This table should not exist any more than a table of “Things” such exist.
And the reason you are beyond any real help is “attribute_id” which tell us that your schema is a total disaster of data and meta data mixed together in a non-RDBMS written in awful SQL. Based on cleaning up bad SQL for 30 years, it looks like you are an OO
programmer who never unlearned his prior mindset.
Why did you allow an encoding schema with blanks? Why do you have so many NULL-able columns?
SELECT DISTINCT is very rare in a properly designed schema. The DRI references assure that rows cam be matched. To get you started, look at this skeleton:
CREATE TABLE Products
(product_gtin CHAR(15) NOT NULL PRIMARY KEY,
product_type CHAR(2) DEFAULT 'XX' NOT NULL
CHECK (product_type IN ('AP', 'IB', 'HR', 'XX'))
The table name is a plural noun because it models a set (NOT an OO class).
The GTIN is an industry standard identifiers, and not have to invent our own.
The product_type (not blood_type, not automobile_body_type!) has a constraint that assures it is never NULL and never blank; I invented 'XX' as a default.
You need more help than you can get in a forum, but if you will follow Netiquette and post the DDL, we can get you started.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
I want to do something like this in a SELECT where I set the value of one field based on another. Is this possible. If not are there any alternatives? Thanks
CASE WHEN [var_cpnt_brkpt_ct] = '0' THEN [enrc_cpnt_var_price_rt] = '0'There is no CASE statement in SQL; we are a declarative language. We have a case expression! There is no control flow, like you are trying to write. You do not even know that fields are columns. This is as silly
as asking for the color the feathers on a fish.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in
Sets / Trees and Hierarchies in SQL
Thank you for your support. Good day Sir. -
Case statement and Decode function both are not working in Select cursor.
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. On the other hand both the things work in just select statement.
See the first column in select (PAR_FLAG), I need to have this evaluated along with other fields. Can you please suggest some thing to make this work. And also I would like to
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Author : Amit Juneja
Date : 06/20/2011
Description:
Updates the Diamond MEMBER_MASTER table with the values from
INC.MEM_NJ_HN_MEMBER_XREF table.
declare
rec_cnt number(12) := 0;
commit_cnt number(4) := 0;
cursor select_cur is
Select DECODE(1,
(Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY'))),
'Y',
'N') PAR_FLAG,
H.SEQ_ELIG_HIST,
H.SEQ_MEMB_ID,
H.SEQ_SUBS_ID,
H.SUBSCRIBER_ID,
H.PERSON_NUMBER,
H.EFFECTIVE_DATE,
H.TERM_DATE,
H.TERM_REASON,
H.RELATIONSHIP_CODE,
H.SEQ_GROUP_ID,
H.PLAN_CODE,
H.LINE_OF_BUSINESS,
H.RIDER_CODE_1,
H.RIDER_CODE_2,
H.RIDER_CODE_3,
H.RIDER_CODE_4,
H.RIDER_CODE_5,
H.RIDER_CODE_6,
H.RIDER_CODE_7,
H.RIDER_CODE_8,
H.MEDICARE_STATUS_FLG,
H.OTHER_STATUS_FLAG,
H.HIRE_DATE,
H.ELIG_STATUS,
H.PREM_OVERRIDE_STEP,
H.PREM_OVERRIDE_AMT,
H.PREM_OVERRIDE_CODE,
H.SEQ_PROV_ID,
H.IPA_ID,
H.PANEL_ID,
H.SEQ_PROV_2_ID,
H.SECURITY_CODE,
H.INSERT_DATETIME,
H.INSERT_USER,
H.INSERT_PROCESS,
H.UPDATE_DATETIME,
H.UPDATE_USER,
H.UPDATE_PROCESS,
H.USER_DEFINED_1,
H.SALARY,
H.PEC_END_DATE,
H.REASON_CODE,
H.PEC_WAIVED,
H.BILL_EFFECTIVE_FROM_DATE,
H.BILLED_THRU_DATE,
H.PAID_THRU_DATE,
H.SUBSC_DEPT,
H.SUBSC_LOCATION,
H.USE_EFT_FLG,
H.BENEFIT_START_DATE,
H.SEQ_ENROLLMENT_RULE,
H.MCARE_RISK_ACCRETION_DATE,
H.MCARE_RISK_DELETION_DATE,
H.MCARE_RISK_REFUSED_DATE,
H.COMMENTS,
H.USER_DEFINED_2,
H.USER_DEFINED_3,
H.RATE_TYPE,
H.PCPAA_OCCURRED,
H.PRIVACY_ON,
H.PCP_CHANGE_REASON,
H.SITE_CODE,
H.SEQ_SITE_ADDRESS_ID,
PM.seq_prov_id rendered_prov
from hsd_member_elig_history H,
INC.PCP_REASSIGN_RPRT_DATA P,
hsd_prov_master PM
where P.subscriber_id = H.subscriber_id
and P.rendered_pcp = PM.provider_ID
and H.elig_status = 'Y'
and (H.term_date is NULL or H.term_date >= last_day(sysdate))
order by H.Seq_memb_id;
begin
for C in select_cur loop
rec_cnt := rec_cnt + 1;
update hsd_member_elig_history
set term_date = TRUNC(SYSDATE - 1),
term_reason = 'PCPTR',
update_datetime = SYSDATE,
update_user = USER,
update_process = 'TD33615'
where seq_elig_hist = C.seq_elig_hist
and seq_memb_id = C.seq_memb_id;
INSERT INTO HSD_MEMBER_ELIG_HISTORY
(SEQ_ELIG_HIST,
SEQ_MEMB_ID,
SEQ_SUBS_ID,
SUBSCRIBER_ID,
PERSON_NUMBER,
EFFECTIVE_DATE,
TERM_DATE,
TERM_REASON,
RELATIONSHIP_CODE,
SEQ_GROUP_ID,
PLAN_CODE,
LINE_OF_BUSINESS,
RIDER_CODE_1,
RIDER_CODE_2,
RIDER_CODE_3,
RIDER_CODE_4,
RIDER_CODE_5,
RIDER_CODE_6,
RIDER_CODE_7,
RIDER_CODE_8,
MEDICARE_STATUS_FLG,
OTHER_STATUS_FLAG,
HIRE_DATE,
ELIG_STATUS,
PREM_OVERRIDE_STEP,
PREM_OVERRIDE_AMT,
PREM_OVERRIDE_CODE,
SEQ_PROV_ID,
IPA_ID,
PANEL_ID,
SEQ_PROV_2_ID,
SECURITY_CODE,
INSERT_DATETIME,
INSERT_USER,
INSERT_PROCESS,
UPDATE_DATETIME,
UPDATE_USER,
UPDATE_PROCESS,
USER_DEFINED_1,
SALARY,
PEC_END_DATE,
REASON_CODE,
PEC_WAIVED,
BILL_EFFECTIVE_FROM_DATE,
BILLED_THRU_DATE,
PAID_THRU_DATE,
SUBSC_DEPT,
SUBSC_LOCATION,
USE_EFT_FLG,
BENEFIT_START_DATE,
SEQ_ENROLLMENT_RULE,
MCARE_RISK_ACCRETION_DATE,
MCARE_RISK_DELETION_DATE,
MCARE_RISK_REFUSED_DATE,
COMMENTS,
USER_DEFINED_2,
USER_DEFINED_3,
RATE_TYPE,
PCPAA_OCCURRED,
PRIVACY_ON,
PCP_CHANGE_REASON,
SITE_CODE,
SEQ_SITE_ADDRESS_ID)
values
(hsd_seq_elig_hist.nextval,
C.SEQ_MEMB_ID,
C.SEQ_SUBS_ID,
C.SUBSCRIBER_ID,
C.PERSON_NUMBER,
trunc(SYSDATE),
C.TERM_DATE,
C.TERM_REASON,
C.RELATIONSHIP_CODE,
C.SEQ_GROUP_ID,
C.PLAN_CODE,
C.LINE_OF_BUSINESS,
C.RIDER_CODE_1,
C.RIDER_CODE_2,
C.RIDER_CODE_3,
C.RIDER_CODE_4,
C.RIDER_CODE_5,
C.RIDER_CODE_6,
C.RIDER_CODE_7,
C.RIDER_CODE_8,
C.MEDICARE_STATUS_FLG,
C.OTHER_STATUS_FLAG,
C.HIRE_DATE,
C.ELIG_STATUS,
C.PREM_OVERRIDE_STEP,
C.PREM_OVERRIDE_AMT,
C.PREM_OVERRIDE_CODE,
C.SEQ_PROV_ID,
C.IPA_ID,
C.PANEL_ID,
C.SEQ_PROV_2_ID,
C.SECURITY_CODE,
SYSDATE,
USER,
'TD33615',
SYSDATE,
USER,
'TD33615',
C.USER_DEFINED_1,
C.SALARY,
C.PEC_END_DATE,
C.REASON_CODE,
C.PEC_WAIVED,
C.BILL_EFFECTIVE_FROM_DATE,
C.BILLED_THRU_DATE,
C.PAID_THRU_DATE,
C.SUBSC_DEPT,
C.SUBSC_LOCATION,
C.USE_EFT_FLG,
C.BENEFIT_START_DATE,
C.SEQ_ENROLLMENT_RULE,
C.MCARE_RISK_ACCRETION_DATE,
C.MCARE_RISK_DELETION_DATE,
C.MCARE_RISK_REFUSED_DATE,
C.COMMENTS,
C.USER_DEFINED_2,
C.USER_DEFINED_3,
C.RATE_TYPE,
C.PCPAA_OCCURRED,
C.PRIVACY_ON,
C.PCP_CHANGE_REASON,
C.SITE_CODE,
C.SEQ_SITE_ADDRESS_ID);
commit_cnt := commit_cnt + 1;
if (commit_cnt = 1000) then
dbms_output.put_line('Committed updates for 1000 records.');
commit;
commit_cnt := 0;
end if;
end loop;
commit;
dbms_output.put_line('Total number of MEMBER_ELIG_HISTROY records inserted : ' ||
rec_cnt);
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
end;user10305724 wrote:
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. Please define what you mean by not working even if your computer screen is near the internet we can't see it.
You should also look at the FAQ about how to ask a question
SQL and PL/SQL FAQ
Particularly *9) Formatting with {noformat}{noformat} Tags* and posting your version.
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Does this mean you are using 8i? Then scalar sub queries - selects within the select list, are not supported, along with CASE in PL/SQL.
Select DECODE(1,
* (Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY')))*,
'Y',
'N') PAR_FLAG,
>
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
OSTC Query Not Showing Correct Percent If Component is Changed
Hello gurus and experts...here is an interesting question:
Question: Why does a query not report proper Sales Tax Code percentage from OSTC table when a component is updated?
Sales Tax Code (STC) of CA-37B, with a rate of 10.25% is made up of three parts:
California (CA) State Tax Jurisdiction of "CA" with a rate of 7.00%,
County Tax Jurisdiction of "CA-37" at a rate of 1.75%,
City Tax Jurisdiction of "CA-37B" with a rate of 1.50%, and the effective date is set at 31 Dec 2008 (in the past).
When the City Tax Jurisdiction is changed to 1.00% and date of 31 Dec 2009, the OSTC of CA-37B should be 9.75%.
However, when a query is run on the OSTC table it strangely reports the old 10.25% (on the Sales Tax Code window it shows correctly as 9.75%).
Here is the query - very simple...as about as simple as it gets...
SELECT
T0.Code,
T0.Name,
T0.Rate AS 'Total Tax Percentage',
T0.Freight AS 'Freight Taxable?'
FROM OSTC T0
ORDER BY T0.Code
IF we go back to the Sales Tax Code Window and change anything (description, one of the components, etc) and hit the update button, then the query reports the correct percentage.
Am I missing something here? I would imagine that the system must be doing something and I cannot believe the workaround is just go back and update something in the Sales Tax Code window - there are a ton of updates to do with taxes each year! Trying to remember which component was updated can cause real confusion. SAP B1 does a ton of automatic updates all over the system - why would it just be this area of information in OSTC???
Thanks for reading the post, and many more thanks for your help and suggestions - ZalOK - Question Answered - had nothing to do with the query - user did not hit "Update" two times when doing the City Tax Jurisdiction Update...
I knew SAP would be doing an auto update - has to!!!
Thanks all - Zal -
Query not displaying correct data
hi all
my query is not displaying correct data.
in data target secondary sales is showing 1.800 value but in query it is showing
2.00.my requirement is my query shuld show 1.800 value. i also tried to change decimal points but not changes has happend.plz let me knw what is the problem
thanks in advance
shalini guptaWith which u r reconciling the data.
With R3 or Cube.
I think check ur key figure, have u taken the key figure 'with TAX' one or with out tax one??
Regards,
Manoj. -
Firefox 33 HTML select elements do not display correctly
HTML form <select> elements do not display options correctly in Firefox 33.
For example:
<select id="field_4" class="mainForm" name="field_4">
<option value=""></option>
<option value="submitted"></option>
<option value="pending"></option>
<option value="discarded"></option>
<option value="all"></option>
</select>
should display a drop down with 5 elements (first one blank) but no elements at all are displayed.
The bounding box does not seem to be computed correctly so no options display.
I have observed this issue on multiple pages. These pages displayed correctly in older version of Firefox and they display correctly under IE. The problem occurs with no addons or additional themes installed. The problem does not occur in SafeMode so I suspect that it is theme related but the Default 33.0 theme is the only installed theme and it cannot be disabled outside of SafeMode. I tried installing and changing multiple themes without success. The problem persists after restarting Firefox and after rebooting the computer and even after uninstalling and re-installing Firefox.
I can supply a screen shot if needed.You can try to disable hardware acceleration in Firefox.
*Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
You need to close and restart Firefox after toggling this setting.
*https://support.mozilla.org/kb/upgrade-graphics-drivers-use-hardware-acceleration
If it works in Safe Mode and in normal mode with all extensions (Firefox/Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
*https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes -
Please Help: Trouble with nested CASE statement and comparing dates
Please tell me why the query below is always returning the bold null even when the start_date of OLD is greater than or equal to the start_date of NEW.
What I want to do is get the difference of the start_dates of two statuses ( Start_date of OLD - Start_date of NEW) if
1. end_date of NEW is not null
2. start_date of OLD is greater than start_date of NEW
else return null.
select id,
case when max(end_date) keep (dense_rank last order by decode(request_wflow_status,'New',1,0),start_date) is null then
null
else
case when max(decode(status,'OLD',start_date,null)) > max(decode(status,'NEW',start_date,null))
then max(decode(status,'OLD',start_date,null)) - max(decode(status,'NEW',start_date,null))
else
null
end
end result
from cc_request_status where id =1
group by id;Avinash,
Thank you for your help.. Here is a more description of my problem..
Here is a sample of data I have for a table with four columns (id,status,start_date,end_date)
What I need to do is to get difference of the start dates of the maximum available dates, if data is valid. The pseducode is as follows:
IF end_date of New status is null
THEN return null
ELSE
IF start_date of old >= start_date of new
THEN return (start_date of old - start_date of new)
ELSE return null
I used the following query but always return the bold null
select id,
(case when max(end_date) keep (dense_rank last order by decode(status,'new',1,0),start_date) is null then
null
else
(case when max(decode(status,'old',start_date,null)) >=
max(decode(status,'new',start_date,null))
then max(decode(status,'old',start_date,null)) - max(decode(status,'new',start_date,null))
else
null
end)
end) result
from tbl where id =1
Based on the below sample, I expected to get the following result; 14-Mar-07 - 16-Feb-07 which is the difference of the maximum start_dates of the two statuses. However the query is not working.. Please help me.. Thank you..
Id Status start_date end_date
1 new 03-Feb-07 07-Feb-07
1 new 16-Feb-07 21-Feb-07
1 old '10-Mar-07 12-Mar-07
1 old '14-Mar-07 16-Mar-07 -
Field selection in query not appropriate
hi all,
i have written following code.
SELECT EBELN BUKRS BSART AEDAT LIFNR ERNAM EKGRP FROM EKKO
INTO CORRESPONDING FIELDS OF TABLE IT_EKKO
WHERE BUKRS IN S_BUKRS
AND BSART IN S_BSART
AND AEDAT IN S_AEDAT
AND FRGKE EQ 'R'.
*SELECT * FROM EKKO INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
IF NOT IT_EKKO[] IS INITIAL.
SELECT EBELN EBELP VGABE MENGE BWART FROM EKBE INTO
CORRESPONDING FIELDS OF TABLE IT_EKBE
FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN EQ IT_EKKO-EBELN
VGABE EQ '1'.
endif.
now in the above query in it_ekbe table i am getting two line item for doc. no say 75100.
but if i am putting the same doc no in ekbe table in se16 i am getting three line items for same selection as in above query
where doc no = 75100
and vgabe = 1.
plz help.
regards,
AshmitaSELECT EBELN EBELP VGABE MENGE BWART FROM EKBE INTO
CORRESPONDING FIELDS OF TABLE IT_EKBE
FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN EQ IT_EKKO-EBELN
VGABE EQ '1'.
Press F1 on for all entries and read it , you will come to know -
After BI Stats installation: Why is this query not reporting on my query?
Hi,
ok, so I thought I was done with BI Stats installation and I run a query:
Detailed Query Runtime Statistics: Analysis 0TCT_MC02_Q0200 0TCT_MC02
which came with the installation.
I see query QueryColleague in this query with the information:
Time = 21.992
Time:Ste =29.480
Counter = 0
1.
What is the significance of these 3 figures (Time, Time:Ste, Counter)? Does it in any way give a sense of the performance of the query?
2.
Under the Settings for BI Statistics I verified and QueryColleague was set as:
Statistics = D
OLAP detail level = (blank)
I have a query QueryMyOwn which following the installation guidelines, I set up as:
Statistics = X
OLAP detail level = 2
I have since run QueryMyOwn a and run the delta process chains again but this query still not does appear in this Detailed Query Runtime Statistics. Any idea what may be going on?
3.
Am I misinterpreting this report? I thought it was going to show a list of queries which BS Stats has collected data and reporting on them.
4.
Which of the many queries which come with the BI Stats have you found useful so far? I will appreciate the reason. Any particular one standing out if you need to track why a particular report may not be performing well?
ThanksHi,
I think you are viewing the queries from Admin cockpit 0TCT_MC02_Q0200 which has filter to display the query that had been executed in last 24 hours.
Most of the queries from Admin Cockpit will be help you to monitor the data load stats, which load taken long time to complete including the process chains, DTP etc. There are some other queries with have conditional / Expection which filter the data based on top 10 process etc.
Few Queries that was useful to me are
0TCT_MC22_Q0104 - Long term trends in total runtime
0TCT_MC12_Q0110 - Process status
0TCT_MC01_Q0122 - Deviation in runtime of BI Application Object
Hope it helps,
Cheers,
Balaji
Maybe you are looking for
-
6.0.3 Error During Disc Initialization for both DVD+R and Disc Image - Help
I've been a mac user for a few years now, but I just bought a new MacBook, and my first superdrive! I'm all excited to test out the new hardware along with iDVD. I've made a rather simple DVD setup and the first time through it was encoding for about
-
Hello All: I am very new to Power Shell and need some help: I have 224 GAL's on our Exchange System (Ex 2007) where, I need to count the total number of email addresses/display names assigned to each GAL. I am not sure how to set up a for-next loop
-
How can you connect Envy Touchsmart 14k-120US to LG LED TV using an HDMI cable given that the laptop screen doesnt work? The customer service guy confidently told me 'Sir please try Fn+F4' but that doesnt work. Any help would be appreciated.
-
Hi, I have a new ZEN player. The complete AC adpator is $29.99 plus shipping. All it is, is a 5 volt charger like the one I have for my nomad 2, nomad Zen Xtra and nomad Zen touch plus an USB adaptor. Well, I have lots of the old 5 v 2.4 amp wall cha
-
An alternative to the buggy e2200 Killer Ethernet Driver/Software (GE60)
After several crashes related to the bad Bigfoot Killer Ethernet software and driver, I decided to dig a little deeper. Most people will be able to tell you that the "Killer Ethernet" is fairy pointless, I didn't buy the laptop for it at any rate. It