Switch case in select statement
I have got the following message, while executing the SQL Query. Appreciate any help pointing what is wrong...
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'CASE'.
SELECT TOP 1 UP.DATAID, UP.START_TIME, datediff(day, UP.START_TIME, getutcdate()) as DayGap
CASE DayGap
WHEN 0
THEN 'SAME DAY'
WHEN > 0
THEN 'new record'
ELSE 'other'
END as FinalRe
FROM MTP.USERPROGRESS as UP
where UP.MDATAID = 575 AND UP.LSTATUS = 2
tried the following also, but no luck
SELECT TOP 1 DATAID, START_TIME, datediff(day, START_TIME, getutcdate() as DayGap
SWITCH((datediff(day, START_TIME, getutcdate()) = 0)'ITSZERO', (datediff(day, START_TIME, getutcdate()) > 0)'GT1', TRUE, 'n')
FROM MTP.USERPROGRESS
where MDATAID = 575 AND LSTATUS = 2
SELECT TOP 1 UP.DATAID, UP.START_TIME, datediff(day, UP.START_TIME, getutcdate()) as DayGap,
CASE when DayGap =0
THEN 'SAME DAY'
WHEN DayGap > 0
THEN 'new record'
ELSE 'other'
END as FinalRe
FROM MTP.USERPROGRESS as UP
where UP.MDATAID = 575 AND UP.LSTATUS = 2
-Prashanth
Similar Messages
-
Case in Select Statement - Ramya
Hi All,
Could any body help me out ,how to use the CASE in select Statement
Thanks in Advancehere is an example:
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select empno,
2 ename,
3 job,
4 case when job = 'PRESIDENT' then 1
5 when job = 'MANAGER' then 2
6 when job = 'SUPERVISOR' then 3
7 else 4
8 end rank
9 from emp;
EMPNO ENAME JOB RANK
7566 JONES MANAGER 2
7902 FORD ANALYST 4
7839 KING PRESIDENT 1
7698 BLAKE MANAGER 2
7782 CLARK MANAGER 2
7369 SMITH CLERK 4
7499 ALLEN SALESMAN 4
7521 WARD SALESMAN 4
7654 MARTIN SALESMAN 4
7788 SCOTT ANALYST 4
7844 TURNER SALESMAN 4
7876 ADAMS CLERK 4
7900 JAMES CLERK 4
7934 MILLER CLERK 4
14 rows selected.
SQL> -
Use of Case in Select statement
Hi All,
Can anyone tell me whats wrong im doing in the following select statement. I am selecting most this fields from Global Temperory Table and few from normal DB tables.
select h.Taskid,h.Flowid,fd.DESCRIPTION Flowname,h.Stepid, sd.DESCRIPTION Stepname,h.Lockby,ud.USERNAME,h.Status,case Date_initiated when (Currval.Testid = Nextval.Testid) Then Date_initiated := NULL Else Date_initiated := Date_initiated End case,case UserTime When ((Currval-1).Testid IS NULL or Currval.Testid <> (Currval-1).Testid) Then UserTime := StartTime When (Currval.Testid = (Currval-1).Testid or Currval.Testid <> Nextval.Testid or Nextval.Testid IS NULL) Then UserTime = (Currval-1).Endtime End case,case StartTime When(Currval.Stepid = Nextval.Stepid or Currval.Stepid=9999) Then StartTime := NULL Else StartTime := StartTime End case,h.EndTime,h.LockTime,h.Drawer,h.FileNo,h.DocType from GlobalTempTest h inner join USERDEFINITION ud on h.Lockby=ud.USERID inner join FLOWDEFINITION fd on h.Flowid=fd.FLOWID inner join STEPDEFINITION sd on (h.Stepid=sd.STEPID and h.Flowid=sd.FLOWID)
Hope so get some response soon.
Thanks in AdvanceYou have to rewrite your code like this:
CASE WHEN (Currval.Testid = Nextval.Testid) THEN NULL
ELSE Date_initiated
END New_Date_initiatedCurrval/Nextval as shown in your example will not work. Please explain what you mean by previous value comparison.
C. -
Hello,
in Oracle8 I've the following problem:
The statement
SELECT ''' | ''||' || 'rpad'
|| '(''' || column_name
|| ''',' ||
(CASE WHEN (data_type = 'VARCHAR2' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'CHAR' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'CLOB' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'DATE' AND
data_length != 19) THEN
to_number('19')
ELSE
data_length
END )
|| ', '' '')||' AS column_name
FROM dba_tab_columns
WHERE
table_name = upper('DBA_TABLES') AND
owner = upper('SYS')
ORDER BY column_id;
works fine but defining the same statement as a cursor in a PL/SQL Procedure, I got a
Error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
The same procedure can be compiled in Oracle9i without errors.
Does anybody know if there are any restrictions using CASE statements in a PL/SQL CURSOR in Oracle8?
Thanks
PatricHi,
I am encountering the same problem.
Can u suggest the decode statement used instead of case
for this select clause which uses the CASE statement ?
SELECT
CASE
WHEN S.cmpy_num = S.cpty_borg_num THEN
''OURS''
ELSE
''THEIRS''
END AS SDIOwner,
From TABLE -
Case sensitivity select statement without using native sql
please help me ,
i have a selection screen as select-options : s_vbeln, s_kunnr(mandt),s_matnr and
p_name as a parameter (type name1) which is case sensitive in sap abap database and i want to get
output from these fields in an alv.[vbeln,kunnr,name1,audat,auart,matnr,kwmeng,netwr]
How to do it? Can any one give me solution please.[i have to handle case sensitivity plz give me solution]this is my code : but its not working as i expected plz tell me where did i went wrong...
type-pools slis.
tables : vbak , vbap.
select-options : s_vbeln for vbak-vbeln,
s_kunnr for vbak-kunnr,
s_matnr for vbap-matnr.
parameters p_name1 type NAME1_GP.
ranges r_name for kna1-name1.
types : begin of ty_vbak,
vbeln type vbeln_va,
audat type audat,
auart type auart,
kunnr type kunnr,
end of ty_vbak,
begin of ty_vbap,
vbeln type vbeln_va,
matnr type matnr,
netwr type netwr_ap,
kwmeng type kwmeng,
end of ty_vbap,
begin of ty_kna1,
kunnr type kunnr,
name1 type name1,
end of ty_kna1,
begin of ty_final,
vbeln type vbeln_va,
audat type audat,
auart type auart,
matnr type matnr,
netwr type netwr_ap,
kwmeng type kwmeng,
kunnr type kunnr,
name1 type name1,
end of ty_final.
data : t_vbak type standard table of ty_vbak initial size 1,
t_vbap type standard table of ty_vbap initial size 1,
t_kna1 type standard table of ty_kna1 initial size 1.
data : t_final type standard table of ty_final initial size 1,
w_final type ty_final,
w_vbap type ty_vbap,
w_kna1 type ty_kna1,
w_vbak type ty_vbak.
data : t_fcat type slis_t_fieldcat_alv,
w_fcat type slis_fieldcat_alv.
DATA T_FINAL2 TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 1.
data v_name1 type name1.
if p_name1 is not initial.
r_name-sign = 'I'.
r_name-option = 'EQ'.
if p_name1 ca '*'.
r_name-option = 'CP'.
endif.
r_name-low = p_name1.
append r_name.
endif.
start-of-selection.
select vbeln audat auart kunnr from vbak
into table t_vbak
where vbeln in s_vbeln and
kunnr in s_kunnr.
if sy-subrc <> 0.
message 'plz enter a valid entry' type 'I'.
leave list-processing.
endif.
if t_vbak[] is not initial.
select vbeln matnr netwr kwmeng from vbap
into table t_vbap
for all entries in t_vbak
where vbeln = t_vbak-vbeln and
matnr in s_matnr.
if sy-subrc <> 0.
message 'no rec found' type 'I'.
leave list-processing.
endif.
select kunnr name1 from kna1
into table t_kna1
for all entries in t_vbak
where kunnr = t_vbak-kunnr.
if sy-subrc = 0.
sort t_kna1 by kunnr.
endif.
endif.
end-of-selection.
loop at t_vbap into w_vbap.
read table t_vbak into w_vbak with key vbeln = w_vbap-vbeln binary search.
read table t_kna1 into w_kna1 with key kunnr = w_vbak-kunnr binary search.
w_final-vbeln = w_vbak-vbeln.
w_final-audat = w_vbak-audat.
w_final-auart = w_vbak-auart.
w_final-matnr = w_vbap-matnr.
w_final-netwr = w_vbap-netwr.
w_final-kwmeng = w_vbap-kwmeng.
w_final-kunnr = w_kna1-kunnr.
w_final-name1 = w_kna1-name1.
append w_final to t_final.
endloop.
delete t_final where name1 not in r_name.
perform sub_fill_fcat using 'VBELN' 'SALE ORDER NUM'.
perform sub_fill_fcat using 'KUNNR' 'CUSTOMER NUMBER'.
perform sub_fill_fcat using 'NAME1' 'NAME OF A CUST'.
perform sub_fill_fcat using 'AUDAT' 'SALE ORDER DATE'.
perform sub_fill_fcat using 'AUART' 'SALE DOC TYPE'.
perform sub_fill_fcat using 'MATNR' 'MATERIAL NUM'.
perform sub_fill_fcat using 'KWMENG' 'QUANTITY'.
perform sub_fill_fcat using 'NETWR' 'PRICE'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_FCAT
TABLES
T_OUTTAB = T_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
*& Form SUB_FILL_FCAT
* text
* -->P_0389 text
* -->P_0390 text
FORM SUB_FILL_FCAT USING P_FNAM P_TEXT.
clear w_fcat.
w_fcat-fieldname = p_fnam.
w_fcat-seltext_m = p_text.
append w_fcat to t_fcat.
ENDFORM. -
Hi friends, can any one give me the possible select statement which are used in Report query with some code examples
Hi,
SELECT
Syntax
SELECT result
FROM source
INTO|APPENDING target
[[FOR ALL ENTRIES IN itab] WHERE sql_cond]
Effect
SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
E.g.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT c~carrname p~connid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON p~carrid = c~carrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON f~carrid = p~carrid
AND f~connid = p~connid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Jogdand M B -
Case or decode in select statement for comparison
Hi,
How can I do a comparison
like
if sal < 50, output 1.1 * comm
if sal > 50 and < = 100 output 1.2 * comm
else output comm
in a single select statement.
I tried using case and decode but I am not sure how to use it in comparison operations.
Please helpuse the 'case' construct:
SELECT
NORMAL_FIELD
, (CASE
WHEN (SAL < 50) THEN 1.1 * COMM
WHEN (SAL > 50) AND (SAL <= 100) THEN 1.2 * COMM
ELSE COMM
END
) AS CALCULATED_COMM
FROM
TB_xxxx
WHERE xxxx
hope this helps -
Case sensitive statement in the select-statement
Hi All,
i have a table in the abap-dictionary filled with names...when i try to select them with the select-statement with condition:
table-name_column like 'some_name'
I have encountered some problems...the inquiry is case-sensitive. What i want to do is to read the value from the abap-dictionary table uppercase or lowercase and compare it with the needed value also translated in uppercase or lowercase.
The only idea i have is to select all values of the dictionary table into an internal table and to translate the values there in uppercase or lowercase and then to loop trough it. But this approach would cost a lot of performance.
Do someone has an other proposal?check...
Select statement
It would be difficult , because it is based on how data is stored in the data base , now consider the scenario of the system i am using , we can material description as 'test' or 'TEST' , 'Test' .
If in your system there are only stored in either caps or small the you can perform the select twice .
But i myself dont find it to be such a good solution , but you can give it a try
There is one more solution specific to material description ,and that is in the table MAKT there is a field MAKTG , which stored the description in uppercase , so for this you can first convert the description to uppercase and then perform select on this field -
Problems with a result in a switch/case control statement
I am having troubles with a switch/case statement in which I am trying to get a result returned from different operators. The problem is that the result always returns 0 no matter what I put in the driver class.
The class where the result needs to be returned looks like this:
public class Calculator
private int num1;
private int num2;
private char operator;
private int result;
public Calculator(int num1, char operator, int num2)
this.num1 = num1;
this.operator = operator;
this.num2 = num2;
} // end constructor
public int getNum1()
return num1;
public char getOperator()
return operator;
public int getNum2()
return num2;
public int getResult()
return result;
public int calculate()
switch(operator)
case '+':
int result = num1 + num2;
break;
} // end case '+'
case '-':
int result = num1 - num2;
break;
} // end case '-'
case '*':
int result = num1 * num2;
break;
} // end case '*'
case '/':
int result = num1 / num2;
break;
} // end case '/'
case '%':
int result = num1 % num2;
break;
} // end case '%'
} // end switch
return result;
public String toString()
String message = (num1) + " " + (operator)
+ " " + (num2) + " " + "=" + " " + result + "\n";
return message;
} // end class
The driver class looks like this:
import javax.swing.JOptionPane;
import java.lang.StringBuffer;
public class CalculatorApp
public static void main (String[] args) // begin main
String choice = "";
while (!(choice.equalsIgnoreCase("x"))) // begin while loop
String number1 = JOptionPane.showInputDialog(
"Enter a positive integer: ");
String operatorInput = JOptionPane.showInputDialog(
"Enter operator (+, -, *, /, %): ");
String number2 = JOptionPane.showInputDialog(
"Enter another positive integer: ");
int num1;
char operator;
int num2;
num1 = Integer.parseInt(number1);
operator = operatorInput.charAt(0);
num2 = Integer.parseInt(number2);
Calculator calculator = new Calculator(num1, operator, num2);
String message = calculator.toString() + "\n"
+ "Press Enter to conitnue or 'x' to exit.";
choice = JOptionPane.showInputDialog(message);
} // end while loop
System.exit(0);
} // end main
any help would be wonderful! I don't know why the result returned is always 0 but it is. Thanks!
dragwitThe previous poster is correct. You never call the calculate method. If you don't call it, no one's going to call if for you. This stuff doesn't work by magic. I think you've misunderstood your prof's intent in this regard.
However, it still won't work with the changes previously suggested, because declaring an int result in the calculate method will hide the instance field of the same name, which is what your getResult() method retrieves. Don't delare result at all in your calculate method.
That said, it would be architecturally a lot better if the calculate method returned the result rather than storing it back into the instance. -
Break statement not working in switch case
Hi,
I've run into this problem multiple times and have looked up the syntax for a switch statement. The problem with the code below is that when it goes into the first case, it executes the break statement but still executes the next case instead of breaking out of the switch case. Can anyone see whats going wrong?
try
switch (columnProps.getCellType())
case (ExcelConstants.CELL_TYPE_STRING):
excelCell.setCellValue(iterator.getCurrentColumnStringValue());
break;
case (ExcelConstants.CELL_TYPE_NUMERIC):
excelCell.setCellValue(iterator.getCurrentColumnIntValue());
break;
catch (Exception e)
System.out.println(e.toString()):
it executes the break statement but
still executes the next case instead of breaking out
of the switch case. Can anyone see whats going wrong?You can if you put in traces (print statements) in proper places. This will allow you to exactly follow the switch behaviour. -
Help with Switch-Case Statement
How do you get this in a switch-case statement or work with it?
if (age < 70) {
JOptionPane.showMessageDialog(null, "People that are below the 70s are nothing special.");
else if (age > 69 && age < 80) {
JOptionPane.showMessageDialog(null, "People that are in their 70s are called septuagenarian.");
else if (age > 79 && age < 90) {
JOptionPane.showMessageDialog(null, "People that are in their 80s are called octogenarian.");
else if (age > 89 && age < 100) {
JOptionPane.showMessageDialog(null, "People that are in their 90s are called nonagenarian.");
else (age > 99 && age < 110) {
JOptionPane.showMessageDialog(null, "People that are in their 100s are called centenarian.");
}Thanks~As per Java Specification, swtich case expects an integer and boolean cannot be used as param for switch.
In your case switch can be used like this.
int index = age /10;
switch(index) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
Your First case
break;
case 7:
your second case
break;
case 8:
third case
break;
case 9:
fourth case
break;
default:
fifth case
break;
Take note of the break statements. Its very important. But I wont prefer in this case. Code looks awkward and is not so meaningful..... -
DoGet method is called 2 times when a switch-case statement is used
Hello all,
I have a servlet that, when run from browser, runs the doGet method 2 times.
I have a switch case statement within the servlet and when I comment out this servlet, it runs 1 time as expected.
Here is the code:
public class RSSServlet extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("CALLED SERVLET");
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();
DBQueriesRSS queries = new DBQueriesRSS();
String queryType = request.getParameter("queryType");
String strCount = request.getParameter("count");
int count = (strCount != null && !strCount.equalsIgnoreCase("null") && strCount.length() > 0) ?
Integer.parseInt(strCount) : 25;
if(queryType != null && !queryType.equalsIgnoreCase("null") && queryType.length() > 0) {
System.out.println("IN IF STATEMENT");
switch(Integer.parseInt(queryType)) {
case 1 : out.println(queries.getDefault(count));System.out.println("1"); break;
case 11: out.println(queries.getDefault(count));System.out.println("11"); break;
case 21: out.println(queries.getTopDaily(count));System.out.println("21"); break;
case 22: out.println(queries.getTopWeekly(count));System.out.println("22"); break;
case 23: out.println(queries.getTopMonthly(count));System.out.println("23"); break;
case 24: out.println(queries.getTopYearly(count));System.out.println("24"); break;
case 31: out.println(queries.getTopNDailyBW(count));System.out.println("31"); break;
case 32: out.println(queries.getTopNWeeklyBW(count));System.out.println("32"); break;
case 33: out.println(queries.getTopNMonthlyBW(count));System.out.println("33"); break;
case 34: out.println(queries.getTopNYearlyBW(count));System.out.println("34"); break;
default: out.println(queries.getTopWeekly(25));System.out.println("default"); break;
System.out.println("OUT OF SWITCH");
System.out.println("OUT OF IF");
out.close();
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
/** Returns a short description of the servlet.
public String getServletInfo() {
return "Short description";
// </editor-fold>
} The results from running this servlet are:
http://localhost/proxy/RSSServlet??queryType=34&count=66
CALLED SERVLET
IN IF STATEMENT
34
OUT OF SWITCH
OUT OF IF
CALLED SERVLET
IN IF STATEMENT
34
OUT OF SWITCH
OUT OF IFAnyone see anything obvious?
TIA!in your case you want 'count' to be a class attribute rather than a local variable. But yes, incrementing it each time that the method is called will serve your purpose.
-
Case sensitve in selection statement
Hi All
I like to write a select statement which is able to get the values irrespective of case sesitive
ie
select * from table_name where column_name like('%sun%')
selection of columns should happen even the column name is '%SUN%' or '%Sun%' ie '%sun%' should not be case sensitive....Can anyone suggest me query for this
Note: the query needs to work in oracel server. Also changing the session ie alter session set NLS_SORT=BINARY_CI ;
alter session set NLS_COMP=LINGUISTIC; cannot be done.
So please help me to get the selection purely through query
With thanks and regards
AnoopUse LOWER or UPPER,
so, for example:
lower(column_name) like '%sun%'
-- OR
upper(column_name) like '%SUN%' -
Can I test (junit) default case of switch-case statement ?
Hi,
I have a class which has switch-case statements and I am trying to junit test with 100% coverage. My switch-case workes based on enum values.
say my enum values are 1, 2.
switch(getEnumValues) {
case 1:
return "some value";
case 2:
return "some value";
default:
throw new UnsupportedOperationException("No such enum value supported.");
I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.
Edited by: TUIJAVADEV on Nov 4, 2008 4:15 PMyawmark wrote:
TUIJAVADEV wrote:
I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.If your enum values are ONE and TWO, and you have cases for both, then there is no "default case". There is nothing to test.
~If I'm reading the OP correctly, they're 1 and 2, not ONE and TWO. That is, not values of a Java enum.
If this is the case, then the easiest way to test the default case is to break the swtich out into a separate, package-accessible method that takes and arg and passes that onto the switch. (There may be variations on this, depending on how your code is structured.)
However, in a similar vein to what the others are saying, if you already know that you'll only ever have 1 and 2 by the time you get to the switch (maybe because the value comes from an argument to the enclosing method, and you've already unit tested that it appropriately throws an IllegalArgumentException when other values are passed, then there's no need to test the default.
Finally, though if it is ints 1 and 2, rather than a true enum, why not switch to an enum? -
If statement in select statement alias
I have the following select statement. It has the alias Survivors, Deaths and "All Cases". Is it posible to use :P_LANGUAGE variable to say that -- IF :P_LANGUAGE = FRENCH THEN alias are Survivants for survivors, Décès for Deaths, Tous_les_cas for All Cases. Please advise
SELECT ALL T_NTR_MULTIBAR.CAT, T_NTR_MULTIBAR.NUM_CASES_LEFTBAR AS Survivors,
T_NTR_MULTIBAR.NUM_CASES_MIDDLEBAR AS Deaths, T_NTR_MULTIBAR.NUM_CASES_RIGHTBAR AS "All Cases"
FROM T_NTR_MULTIBAR
WHERE INSTANCE_NUM = :P_INSTANCENUM
order by ORDERSYou may not be able to add this condition inside the SQL Statement. But you can add this condition outside the statement, if you're using PL/SQL...
IF :p_language = french THEN
SELECT ALL t_ntr_multibar.cat,
t_ntr_multibar.num_cases_leftbar AS survivors,
t_ntr_multibar.num_cases_middlebar AS deaths,
t_ntr_multibar.num_cases_rightbar AS "All Cases"
ELSE
END IF;
Maybe you are looking for
-
My footage looks posterized in FCP playback
im using FCP 7 and have downloaded all the latest software updates. my footage looks normal when i play it back on my video camera, it's normal when i watch it on quicktime, and even when i export it as a quicktime from FCP. it's also normal when cap
-
that warms my mac book is therefore a matter of software or perhaps I should claim the warranty?
-
I "upgraded" to Mavericks today, and all was fine until I clicked "show evite" from an evite invitation email (which I had already viewed without issue last week. When I try to force quit, a window opens saying "The application Firefox canceled shut
-
Where is the Show menu button that is supposed to be at the bottom of the window
where i sthe Show menu button that is supposed to be at the bottom of the iTunes window that will allow me to move music from one computer library to another?
-
Can songs be deleted directly off the iPod?
Can songs be deleted directly off the iPod without connecting to the computer? A co-worker purchased an iPod but decided he didn't want it and wants to return it so he deleted the program off his computer. He asked me how to get it off the iPod. I to