Case statement
hi.
i have a case statement query. i wonder if in the select statement, can i do computation using different parameter from the main report to subreport?
for example, (qty * parameter)
if parameter = 0, i uses $P{abc} to multiply qty
if parameter > 0, i uses $P{xyz} to multiply qty
in this case, i've writen a sql (as below) but its does not execute.
select ....., (QTY *
case $P{QTY}
when 0 then ' * $P{abc}'
else ' $P{xyz}'
end
from....
hence, what should i do in order to get the right parameter to multiply with? pls guide. thanks.
I'm not sure about these parameter placeholders which are specific to whatever report tool you are using, but the structure would be (assuming the parameter value would never be less than zero):
qty * case when $P{QTY} = 0 then $P{abc} else $P{xyz} end
Similar Messages
-
SQL Expression in decode function or case statement?
Can I put SQL expressions in decode function or case statement?
For example,
select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
from element le;
or
select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
ELSE 'Y'
from element le;
None of the above work.
Can anyone tell me how to make it work?
Is there any workaround?
Thanks,
JYou simply needed and END to your CASE statement;
SQL> with profile_data as (
select 'XXXX_AFTER' name, 1 object_id from dual),
element as (
select 1 profile from dual union all
select 2 from dual)
select le.profile,
case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
THEN 'N'
ELSE 'Y'
END new_col
from element le
PROFILE N
1 Y
2 N -
CASE not found while executing CASE statement on Submit Form
Hi to all APEX users and developers.
I have several APEX applications and they are all working well, but recently I got one strange exception when I try to submit page:
Session: Fetch session header information
...metadata, fetch page info
...Validate item page affinity.
...Validate hidden_protected items.
Add error onto error stack
...Error data:
......message: Error processing request.
......additional_info: ORA-06592: CASE not found while executing CASE statement
......display_location: ON_ERROR_PAGE
......is_internal_error: true
......apex_error_code: APEX.UNHANDLED_ERROR
......ora_sqlcode: -6592
......ora_sqlerrm: ORA-06592: CASE not found while executing CASE statement
.....error_backtrace: ORA-06512: at "APEX_040100.WWV_FLOW", line 9273
......component.type: APEX_APPLICATION_AUTH
......component.id: 41350431648668800
......component.name: MNRFR
...Show Error on Error Page
......Performing rollback
Processes - point: AFTER_ERROR_HEADER
Processes - point: BEFORE_ERROR_FOOTER
End Page Processinga
Page has more than 120 items (most of them are hidden), so my first thought is that page has problem with posting so many items, but APEX error message doesn't hel me at all. Any help would be very appreciated :)
AlmirHi Almir,
actually it is the 100 page item limit. See (http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/limits.htm)
I also had a look into the source code and the code at the position where the error gets raised only supports 100 page items.
Can you have a look into the generated HTML code and look if you have a page items which is mapped to p_t101 or a higher number ?
I will file a bug to show a better error message.
Regards
Patrick
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf -
Case Statement in Answers Filter
Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
Thxziekc wrote:
Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
ThxAccording to your requirements, when the month is January, you want all 12 months; any other number and you want months from 1 to "1 less than the current month number." Yes? Okay, here's what to do:
In the filter on your date column, click on the filter button, convert it to SQL and enter this:
MONTH(tablename.date_column) BETWEEN 1 AND CASE WHEN MONTH(CURRENT_DATE) = 1 THEN 12 ELSE MONTH(CURRENT_DATE)-1 END
Here's the logic:
a) When the current month is January, then the case statement will yield 12 and the filter will be:
WHERE MONTH(tablename.date_column) BETWEEN 1 AND 12 ...or all 12 months.
b) When the current month is any other month, say June, then the case statement will yield one less than the what the month number is, or in this case 5.
WHERE MONTH(tablename.date_column BETWEEN 1 AND 5 ...or all the months from 1 to 5 (Jan through May)
This will give you what you want... -
CASE statement in Calculated column
Hi Frzz,
I have below requirement in Calculated column with CASE statement. Could some one help me how to achieve this with case statement.
String = 0Hello
01Hello
012Hello
0123Hello
If 1st Character of the string is '0' then - 0Hello
1st 2 characters of the String is '01' - 22Hello
1st 3 characters of the String is '01' - 333Hello
1st 4 characters of the String is '01' - 4444Hello
Thank you.
Best Regards,
Krishna.Hi Krishna ,
Using IF and MATCH to do that: ( I took one of the conditions you specified )
IF(match("STRING1",'??0??'),'333Hello',"STRING1")
Output:
Regards,
Krishna Tangudu -
Hi PL/SQL experts,
I'm going a bit loopy here, so could someone please point out what I'm doing wrong with this case statement:
Test procedure is:
CREATE OR REPLACE procedure SCOTT.postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE input_post_code
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
However, I'm getting the following error:
LINE/COL ERROR
37/6 PLS-00103: Encountered the symbol "WHEN" when expecting one of
the following:
:= . ( % ;
On a second note, can I not have the ELSE structure embedded within the case (currently commented out)?
Thanks very much in advance.
DevFixed code:
CREATE OR REPLACE procedure postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END CASE;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
/As VG2 pointed out you were missing some semicolons.
Also, CASE input_post_code was replaced with just CASE since you are doing a searched case.
Also, END at the end of the case statement was replaced with END CASE. -
Case statement in advanced sql
how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table
this is the case statement i am using :
case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
and i get the below error
: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000) -
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 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 -
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 do I use the CASE statement in the where clause?
Hello Everyone,
I have 2 queries that do what I need to do but I am trying to learn how to use the CASE statement.
I have tried to combine these 2 into one query using a case statement but don't get the results I need.
Could use some help on how to use the case syntax to get the results needed.
thanks a lot
select segment_name,
product_type,
count (distinct account_id)
FROM NL_ACCT
where
ind = 'N'
and
EM_ind = 'N'
and product_type in ('TAX','PAY')
and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 60)
GROUP BY 1,2
order by product_type
select segment_name,
product_type,
count (distinct account_id)
FROM NL_ACCT
where
ind = 'N'
and
EM_ind = 'N'
and product_type not in ('TAX','PAY')
and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 30)
group by 1,2
order by product_typeSomething like:
SELECT segment_name, product_type,
SUM(CASE WHEN account_id IN ('TAX','PAY') and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60 THEN 1
ELSE 0 END) tax_pay,
SUM(CASE WHEN account_id NOT IN ('TAX','PAY') and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 30 THEN 1
ELSE 0 END) not_tax_pay
FROM NL_ACCT
WHERE ind = 'N' and
em_ind = 'N' and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60
GROUP BY segment_name, product_type
ORDER BY product_typeNote: You cannor GROUP BY 1,2, you need to explicitly name the columns to group by.
HTH
John -
How can you change a drop down menu's selection in a case statement?
Hi,
I am trying to an array finding vi. This VI will take an existing xml file and after the user has selected his/her equipment, input, output, and frequency it will put all of those options into a string and search the xml file for that exact array name and display it on an output screen. The problem I am having is that my input and outputs selection needs to be a little different depending upon the equipment selected. I thought that I could use a case statement to change the input and output selectable options, but I have run into many snags with it. For one everytime I place a new Input and Output drop down menu in the case statement it wants to place a new one in the front panel (I only want one input and output not three I have two inputs and outputs hidden right now). I believe I am using the case statement wrong... Can anyone help change my input and output selectable options depending upon the equipment selected. Attached is my xml file, Array Find.vi (the original one), and Array Find_Test.vi (this is the one I am trying to modify).
Thanks,
dlovell
Solved!
Go to Solution.
Attachments:
Find Array.zip 126 KBHi dlovell,
There are 2 key things I'd recommend for the code - using property nodes to edit the strings in the combo boxes. Something like the following snippet:
Also, check your CPU in task manager when running the code. It will eat a whole core of your machine (25% quad core, 50% dual, 100% single) - that is because you are running the while loop and polling the control as fast as Windows will allow you to. Using Event Structures is a much more efficient way of working in this example.
Check out the MOD attached
Regards,
Peter D
Attachments:
MOD_Find Array.vi 28 KB -
Please Help!!!
How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
January 2014 January
2013 +/-
Region Entry Exit Total Entry Exit Total (Total of Jan2014-Total of Jan2013)
A 2 3
40 5 7 30 40-30= 10What is a table structure? Sorry cannot test it right now..
SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
FROM tbl
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
CASE STATEMENTS AND CASE EXPRESSIONS IN ORACLE9I PL/SQL
제품 : PL/SQL
작성날짜 : 2001-11-13
CASE STATEMENTS AND CASE EXPRESSIONS IN ORACLE9I PL/SQL
=======================================================
PURPOSE
아래의 자료는 Case 문에서 oracle 8.1.7과 Oracle 9i의 New Feature로 8.1.7에서는
sqlplus 에서만 가능했고, 9i 부터는 pl/sql 까지 가능하다.
Explanation
1. Oracle 8.1.7 Feature
Oracle 8.1.7 에서 Case 문은 Decode 문과 유사하지만, 기존의 decode 문을 쓰는 것보다
더 많은 확장성과 Logical Power와 좋은 성능을 제공한다. 주로 나이와 같이 category 별로
나눌때 주로 사용하고 Syntex는 아래와 같다.
CASE WHEN <cond1> THEN <v1> WHEN <cond2> THEN <v2> ... [ELSE <vn+1> ] END
각각의 WHEN...THEN 절의 argument 는 255 까지 가능하고 이 Limit를 해결하려면
Oracle 8i Reference를 참조하면 된다.
The maximum number of arguments in a CASE expression is 255, and each
WHEN ... THEN pair counts as two arguments. To avoid exceeding the limit of 128 choices,
you can nest CASE expressions. That is expr1 can itself be a CASE expression.
Case Example : 한 회사의 모든 종업원의 평균 봉급을 계산하는데 봉급이 $2000보다 작은경우
2000으로 계산을 하는 방법이 pl/sql을 대신하여 case function을 사용할 수 있다.
SELECT AVG(CASE when e.sal > 2000 THEN e.sal ELSE 2000 end) FROM emp e;
Case Example : 나이를 column으로 가지고 있는 customer table을 예로 들어보자.
SQL> SELECT
2 SUM(CASE WHEN age BETWEEN 70 AND 79 THEN 1 ELSE 0 END) as "70-79",
3 SUM(CASE WHEN age BETWEEN 80 AND 89 THEN 1 ELSE 0 END) as "80-89",
4 SUM(CASE WHEN age BETWEEN 90 AND 99 THEN 1 ELSE 0 END) as "90-99",
5 SUM(CASE WHEN age > 99 THEN 1 ELSE 0 END) as "100+"
6 FROM customer;
70-79 80-89 90-99 100+
4 2 3 1
1 SELECT
2 (CASE WHEN age BETWEEN 70 AND 79 THEN '70-79'
3 WHEN age BETWEEN 80 and 89 THEN '80-89'
4 WHEN age BETWEEN 90 and 99 THEN '90-99'
5 WHEN age > 99 THEN '100+' END) as age_group,
6 COUNT(*) as age_count
7 FROM customer
8 GROUP BY
9 (CASE WHEN age BETWEEN 70 AND 79 THEN '70-79'
10 WHEN age BETWEEN 80 and 89 THEN '80-89'
11 WHEN age BETWEEN 90 and 99 THEN '90-99'
12* WHEN age > 99 THEN '100+' END)
SQL> /
AGE_G AGE_COUNT
100+ 1
70-79 4
80-89 2
90-99 3
Example
2. Oracle 9i Feature
Oracle 9i부터는 pl/sql에서도 case문을 사용할 수 있으면 이것은
복잡한 if-else 구문을 없애고, C언어의 switch문과 같은 기능을 한다.
아래의 9i pl/sql Sample 및 제약 사항을 보면 아래와 같다.
Sample 1:
A simple example demonstrating the proper syntax for a case
statement
using a character variable as the selector. See the section entitled
'Restrictions' at the end of this article for details on which PLSQL
datatypes may appear as a selector in a case statement or
expression.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
begin
case achar
when 'A' then dbms_output.put_line('The description was Excellent');
when 'B' then dbms_output.put_line('The description was Very Good');
when 'C' then dbms_output.put_line('The description was Good');
when 'D' then dbms_output.put_line('The description was Fair');
when 'F' then dbms_output.put_line('The description was Poor');
else dbms_output.put_line('The description was No such Grade');
end case;
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 2:
A simple example demonstrating the proper syntax for a case
expression
using a character variable as the selector. See the section entitled
'Restrictions' at the end of this article for details on which PLSQL
datatypes may appear as a selector in a case statement or
expression.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
description varchar2(20);
begin
description :=
case achar
when 'A' then 'Excellent'
when 'B' then 'Very Good'
when 'C' then 'Good'
when 'D' then 'Fair'
when 'F' then 'Poor'
else 'No such grade'
end;
dbms_output.put_line('The description was ' || description);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
NOTE: The above simple samples demonstrate two subtle differences in the
syntax
required for case statements and expressions.
1) A case STATEMENT is terminated using the 'end case' keywords; a
case
EXPRESSION is terminated using only the 'end' keyword.
2) Each item in a case STATEMENT consists of one or more
statements, each
terminated by a semicolon. Each item in a case expression
consists of
exactly one expression, not terminated by a semicolon.
Sample 3:
Sample 1 demonstrates a simple case statement in which the selector
is
compared for equality with each item in the case statement body.
PL/SQL
also provides a 'searched' case statement as an alternative; rather
than
providing a selector and a list of values, each item in the body of
the
case statement provides its own predicate. This predicate can be any
valid boolean expression, but only one case will be selected.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
begin
case
when achar = 'A' then dbms_output.put_line('The description was
Excellent');
when achar = 'B' then dbms_output.put_line('The description was Very
Good');
when achar = 'C' then dbms_output.put_line('The description was
Good');
when achar = 'D' then dbms_output.put_line('The description was
Fair');
when achar = 'F' then dbms_output.put_line('The description was
Poor');
else dbms_output.put_line('The description was No such Grade');
end case;
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 4:
This sample demonstrates the proper syntax for a case expression of
the
type discussed in Sample 3 above.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
description varchar2(20);
begin
description :=
case
when achar = 'A' then 'Excellent'
when achar = 'B' then 'Very Good'
when achar = 'C' then 'Good'
when achar = 'D' then 'Fair'
when achar = 'F' then 'Poor'
else 'No such grade'
end;
dbms_output.put_line('The description was ' || description);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 5:
This sample demonstrates the use of nested case statements. It is
also
permissable to nest case expressions within a case statement (though
it
is not demonstrated here), but nesting of case statements within a
case
expression is not possible since statements do not return any value.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
anum1 number := &anum1;
anum2 number := &anum2;
answer number;
begin
case anum1
when 1 then case anum2
when 1 then answer := 10;
when 2 then answer := 20;
when 3 then answer := 30;
else answer := 999;
end case;
when 2 then case anum2
when 1 then answer := 15;
when 2 then answer := 25;
when 3 then answer := 35;
else answer := 777;
end case;
else answer := 555;
end case;
dbms_output.put_line('The answer is ' || answer);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 6:
This sample demonstrates nesting of case expressions within another
case
expression. Note again the absence of semicolons to terminate both
the
nested case expression and the individual cases of those
expressions.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
anum1 number := &anum1;
anum2 number := &anum2;
answer number;
begin
answer :=
case anum1
when 1 then case anum2
when 1 then 10
when 2 then 20
when 3 then 30
else 999
end
when 2 then case anum2
when 1 then 15
when 2 then 25
when 3 then 35
else 777
end
else 555
end;
dbms_output.put_line('The answer is ' || answer);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Although PL/SQL anonymous blocks have been used in all of the examples
so far,
case statements and expressions can also be used in procedures,
functions, and
packages with no changes to the syntax.
The following samples are included for completeness and demonstrate the
use of
case statements and/or expressions in each of these scenarios.
Sample 7:
This sample demonstrates use of a case statement in a stored
procedure.
Note that this sample also demonstrates that it is possible for each
of
the items in the case body to consist of more than one statement.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace procedure testcasestmt ( anum IN number ) is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
end;
exec testcasestmt(&anum);
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 8:
This sample demonstrates the use of a case statement in a stored
package.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace package testpkg2 is
procedure testcasestmt ( anum IN number );
function testcasestmt_f ( anum IN number ) return number;
end testpkg2;
create or replace package body testpkg2 is
procedure testcasestmt ( anum IN number ) is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
end;
function testcasestmt_f ( anum IN number ) return number is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
return anum;
end;
end testpkg2;
exec testpkg2.testcasestmt(&anum);
variable numout number
exec :numout := testpkg2.testcasestmt_f(&anum);
print numout
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 9:
This sample demonstrates the use of a case expression in a stored
package.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace package testpkg is
procedure testcase ( anum IN number );
function testcase_f ( anum IN number ) return number;
end testpkg;
create or replace package body testpkg is
procedure testcase ( anum IN number ) is
anumber number := anum;
anothernum number;
begin
anothernum :=
case
when anumber = 1 then anumber + 1
when anumber = 2 then anumber + 2
when anumber = 3 then anumber + 3
when anumber = 4 then anumber + 4
when anumber = 5 then anumber + 5
else 999
end;
dbms_output.put_line('The number was ' || anothernum);
end;
function testcase_f ( anum IN number ) return number is
anumber number := anum;
anothernum number;
begin
anothernum :=
case
when anumber = 1 then anumber + 1
when anumber = 2 then anumber + 2
when anumber = 3 then anumber + 3
when anumber = 4 then anumber + 4
when anumber = 5 then anumber + 5
else 999
end;
dbms_output.put_line('The number was ' || anothernum);
return anothernum;
end;
end testpkg;
variable numout number
exec testpkg.testcase(&anum);
exec :numout := testpkg.testcase_f(&anum);
print numout
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
제약 사항
다음의 databasetype은 case 문에서 지원되지 않는다.
BLOB
BFILE
VARRAY
Nested Table
PL/SQL Record
PL/SQL Version 2 tables (index by tables)
Object type (user-defined type)
All of these types except for object types face a similar restriction
even for if statements (i.e. they cannot be compared for equality directly) so this is unlikely to change for these types. Lack of support for object types is simply an implementation restriction which may be relaxed in future releases.
Reference Ducumment
Oracle 8.1.7 Manual
NOTE:131557.1I have done the following code but doesn't
like the statement of - "case(butNext)". What do you mean "doesn't like" -- did you get an error message?
I'm guessing it won't compile because you're trying to switch on a Button.
I tried something
like "g.fillOval(100,50,70,90, BorderLayout.NORTH)"...no that doesn't make sense. You only use BorderLayout.NORTH when you're adding components to a BorderLayout layout manager. An oval is not a component and fillOval isn't adding a component and Graphics is not a Panel or layout manager.
Would appreciate it if someone could tell me how to position
shapes using the graohic method. I think the problem is that you're confusing shapes with components.
Maybe you are looking for
-
ITunes 10.7 install wants to move my music library.
I need to upgrade iTunes 10.6 on my Windows 7 Lenovo T420 laptop to 10.7 to use my new iPod Classic (replaces my iPod video), and I'm not yet ready to accommodate the changes in iTunes 11. My iTunes music data files have been moved to a large partiti
-
Image size of iPhone 5S is smaller than screen size
When I click any picture with my iPhone 5s, the image size is always 20-30% smaller than screen size. Its like a picture clicked from iPhone 4, is this an issue or is it designed in that way?? Coz Images clicked in potrait mode are always cropped 20-
-
Quicktime not playing Apple ProRes (Proxy) 1080p video - help!
Hey guys I have a Apple ProRes (Proxy) 1080p video sent to me via Firevilla from a friend in the states - which simply says - "will not play - quicktime does not understand the format and may need additional software." All my software updates have be
-
Unknown podcasts category created by itunes 7 not accessible for deletion
I have been using Audio Hijack Pro to record "podcasts" and add them to itunes. After upgrading to itunes 7, these podcasts have been put in :podcasts:unknown podcast: where they can be found by smart playlists, but they do not appear anywhere in the
-
How can i set resolution for monitor
The maximum resolution for my monitor is not shown in the preferences. How can I make my macBook Pro use the display in the highest resolution.