SELECT in CASE

CASE v_res_bl
WHEN 'A' THEN RETURN pkg_a.get_id(c_yes,p_id);
WHEN 'B' THEN RETURN pkg_a.get_id(c_no,p_id);
WHEN 'C' THEN
select a
INTO v_res_bl
from table
join 1
join 2
join 3
where 1
and 2;
select a
INTO v_res_bl
from table
join 1
join 2
join 3
where 2
and 2;
CASE v_res_bl1
WHEN 'A' THEN RETURN pkg_a.get_id(c_yes,p_id);
WHEN 'B' THEN RETURN pkg_a.get_id(c_no,p_id);
END CASE;
END CASE;
Can I use this ? Is it correct?

Well, first you CASE v_res_bl, and in case of 'C' you select into the same variable and CASE another one (v_res_bl1). Is that the logic you want? At least, it is confusing.
Perhaps an IF..ELSIF construction would be more readable and easier to debug or modify, if necessary.
Furthermore, try to use exactly one return command in a function. Assign the desired values to a variable and return that value at the end of the function. Again, this will help in terms of debugging and modifying the function in the future and will be more structured and easier to understand for other developers.
if v_res_bl = 'A' then
   v_ret := xy;
elsif v_res_bl = 'B' then
   v_ret := yz;
elsif v_res_bl = 'C' then
   select...
   select...
   if v_res_bl1 /* please give this another name! */ = 'A' then
      v_ret := ab;
   elsif v_res_bl1 = 'B' then
      v_ret := bc;
   end if;
end if;
return v_ret;Just a proposal...
Regards,
Gerd

Similar Messages

  • SQL query problem - select max (case... aggregate function)

    Hi,
    I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
    select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
    select
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    Any ideas?

    Moved to more sutable forum, sorry.

  • What is the problem with this select include case

    i try to determine according to salary here is the sentence
    Select empno ,ename, sal, (case sal when sal<4000 then .05*sal
    when sal>4000 then .1*sal
    else 0 end) as "Required"
    from emp;
    it give me missing keyword erro
    thanks

    Hi,
    Try this:
    SQL> SELECT
      2  (CASE
      3      WHEN SALARY<4000 THEN .05*SALARY
      4      WHEN SALARY>4000 THEN .1*SALARY
      5      ELSE 0
      6   END
      7   ) REQUIRED
      8   FROM EMP;
      REQUIRED
           440
           650
          1000
           700
           900
           600
           480
           480
          1400
          1350
          1200
      REQUIRED
          1100
           800
           820
           790
           650
          1200
           900
           820
           770
          2400
    21 rows selected.
    SQL>
    Note: Please post your error message.
    Cheers,

  • SQL - Select Help - Case When? Return Value from Second Table?

    Hi - next to folks on this board I am probably somewhere between a Beginner and an Intermediate SQL user.
    Ive been using a case when statement in plsql to find "all those who's status in any program was cancelled during a specific time, but have become or are still active in a second program"
    So, Im effectively trying to return a value from a second table in a case when, but its not liking anthing other than a declared text like 'Yes' or 'No'.
    Here is the select statement - is there another way to do this where I can get the results I need?
    case when pp.party_id in (select pp1.party_id  -- Cancelled clients Active in another program
                                       from asa.program_participation          pp1,
                                            asa.curr_prog_participation_status cpps1
                                      where pp1.program_participation_id = cpps1.program_participation_id
                                        and pp1.party_id = pp.party_id
                                        and cpps1.code_value = 'ACT')
                then 'Yes' else 'No' end  as Active_in_Other_Prg
    So - in place of 'Yes' i basically want the program that they are active in or pp1.program_id, else Null
    It is possible that the client can be active in more than one program as well.
    Any assistance is greatly appreciated, i explored with if's and decodes but I cant get anything to work.
    Batesey

    Sounds like an outer join. See ora doc: Joins
    select p.*
    ,      q.party_id
    ,      q.program_id
    from   table_with_party_id p
    ,    ( select pp1.party_id  -- Cancelled clients Active in another program
           ,      pp1.program_id
           from   asa.program_participation          pp1,
                  asa.curr_prog_participation_status cpps1
           where  pp1.program_participation_id = cpps1.program_participation_id
           and    pp1.party_id = pp.party_id
           and    cpps1.code_value = 'ACT') q
    where p.party_id = q.party_id ( +)
    Note: In the example above there shoudn't be a space between the ( and +), but the forum software automagically converts this to
    The outer join will link show all records from the p table and only records from q if the party_id matches, ie q.party_id and q.program_id  will be null if there is no match.
    edit: added program_id

  • How to select a case sensitive value in SQL with C#

    Hello,
    I have an application that at the begining a user will login with a user name and password which is stored in the database. The SQL statement is as follows:
    "SELECT id_employee FROM employee WHERE employee_number='" + txtUserName.Text + "' AND passWord='" + txtPassword.Text + "'";
    For testing purposes I have set the password to the word test.   The problem is, if the user enters in TEST or TeSt or TESt  it will grant them access. How do I set it to force the correct case?
    I am using SQL 2005 for the database.
    Thanks!
    ~zero

    You can also set Collation while comparing strings:
    "SELECT id_employee FROM employee WHERE employee_number='" + txtUserName.Text + "' COLLATE Latin1_General_CS_AS AND passWord='" + txtPassword.Text + "'  COLLATE Latin1_General_CS_AS";
    All comments about not doing this type of quering using command string, instead of command with parameters, they are apsolutely right.
    Nevertheless i will have only username as a parameter in the command and password will be return value from procedure. I will check for equality of entered password and returned one from command in C# code, and C# is case sensitive. There is a good security model implemented for password in AdventureWorks sample database for SQL Server 2005, in table Person.Contact.
    That model use two fields for password, PasswordHash and PasswordSalt. PasswordSalt is randomly generated hash when password is modified and with that salt, password string is encrypted, which produce PasswordHash. So when you want to authenticate a user, execute a command that will return a row(PasswordHash and PasswordSalt) for entered username, and in application you will encrypt entered username with PasswordSalt. If generated string is equal with the one returned PasswordHash, then you have a valid login. If nothing is returned from command or they are not equal, you have invalid login.

  • How to "select" with case ignored???

    Hi everyone, I need to select a field from table, but the data might be written in low case or upper case, even mixed case. for example, i want to select "test" or "TEST" or "Test" in column, what should I modify in my sql "select column1 from tableA where column1 = 'test'" ???
    Thanks in advance

    How about ignoring punctuation marks etc. E.g. search for ABC yields A.B.C. , A-B-C, A B C, and other combinations if present. Does a tool which does something similar exist?

  • Select query case insensitive for data type VARG

    Hi Experts,
    I am having trouble in retrieving the results from a table using select query.
    I have a table (Users) as below
    Name (VARG)        Number(INTEGER)
    Murthy             0001
    murthy             0002
    when I am querying the table with select query as -
    select * from Users where Name = 'Murthy'
    this query is returning only one record which matches with capital letter of 'M', though both the record names are same.
    I have seen in IBM forum to make the select query as case insensitive using the UPPER key word, I have tried this as below -
    select * from Users where UPPER(Name) = 'MURTHY'
    But this query is not working in my case...
    My DB2 version is 8.1.5
    Can any one please help in fixing this problem...
    Thanks in Advance,
    Murthy

    Hi Murthy,
    your query is the right to one to select both records. I don't see why it doesn't work.
    Are you sure you posted the query that you have executed ?
    What is the result of this query ?
    But i don't really know how an VARG (Varying-length graphic string) will work. It could be that the UPPER-Function will work in another way as it works on VARCHAR.
    regards
    Kay

  • How to select test cases efficiently for a test package?

    Dear experts,
    I would like to ask you if you have found a way administer how to assign test cases to test packages and test packages to testers. For regression tests this assignment remains relatively stable (often the key users).
    Do you know a way to administer this within the solution manager - or do you recommend the old excel table.

    Hello Ragu!
    Thank you for your answer! My question was regarding the organisational side, I didn't get this clear.
    I know how to generate a test package and how to assign a tester to a test package but where do I get the information which test packages I need and which tester to assign to which package.
    Maybe a good option is to assign the tester as a team member on the process step level. Thus the assignments can be listed with SOLAR_EVAL using "Assignments / Test Cases" with option "Display Team Members". This list would help to generate the test packages. The selection of the test cases for the test package has do be done manually because there seems to be no filter for team members.
    Regards,
    Martin

  • Select vs Case Select

    Hi,
    My question maybe a bit stupide but Im not figuring the error.
    This simple vi should:
    - count any paire number und
    - build the sume of every paire number
    in a given array. Only the select function should be used and not the case select.
    Building the sume ist working but counting is not working.
    I ll appreciate any advise.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Select Fct.vi ‏9 KB

    you made a small mistake, when the current value is not "paire" you select "0" and then add 1, it doesn't make sense.
    what you need to do is add 1 if "paire" or keep the previous number
    see this :
    on a side note, it make more sense to use i32 if you are dealing with integers.
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"

  • Select in CASE statement or in IF-THEN-ELSE

    I have been struggling for a week with a problem and still can't solve the way I want.
    Given four text fields in page : p1_name, p1_place_name, p1_place_number and p1_place_init_letter - where user types text and press 'Search' button to see the results.
    p1_name finds results in table EMPLOYEES
    p1_place_name, p1_place_number and p1_place_init_letter find results in table PLACES
    the two tables are linked by id_place field
    I would like reports to be shown depending on search results:
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place = PLACES.id_place then a single report shows only employee row
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place # PLACES.id_place then two reports showing 1) employees with name = :p1_name and 2) places with name, number and init_letter = :p1_.....
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist then a message with 'NO EMPLOYEE' and report shows only places where name, number and init_letter = :p1_.....
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then report shows only employee row where name = :p1_name and message with 'NO PLACE'
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then messages 'NO EMPLOYEE' and 'NO PLACE'
    I do NOT know if it is possible, and if it is, then what do I have to use : IF - THEN - ELSE or CASE ?
    I tried to build HTML report region conditionally shown for each situation, but they do not work the way I want.
    Could you please help me ?
    Thank you in advance !

    Agree with Dan. Use a dedicated report region for a unique query. Use a rendering condition to determine if that reporting region must be rendered (i.e. whether or not that reporting query must be executed ).
    The alternative is creating a function that constructs the SQL query dynamically, based on the user supplied values for page items. Use the function as the source for the reporting region, instead of a SQL statement. (this is similar to creating a ref cursor for a client, minus the actual step to create the ref cursor - instead the source SQL for that ref cursor is returned).
    Also consider asking your Apex questions in the dedicated Apex forum on OTN.

  • Select query, case statment

    Hi,
    I have two tables Registration and Place.
    "Registration" table has Name and Registration_id column and "place" table has Registration_id, task_id and state columns. So both tables have inner join on Registration_id column.
    now one Registration_id has two task_id
    so for example,
    Name
    Registration_id
    task_id
    State
    Vicky
    101
    11
    NY
    Vicky
    101
    12
    CA
    Now in output table "Person",  I have 2 columns, one is Birth and one is Death.
    So one person has 1 Registration_id associated and that Registration_id has two records in "Place" table,
    Now condition is like this, for same Registration_id if task_id = 11 put state value in Birth column and  if task_id = 12 put state value in Death column.
    So for example output (Select query for Person table)should looks like below,
    Name
    Registration_id
    Birth
    Death
    Vicky
    101
    NY
    CA
    So please tell me select query for this output from above 2 source tables which I use to insert records into "Person" table. (Just for information - I have 12 source tables and there are many columns I have to select from these source tables
    and this is the part of that select statement where I am stuck for now). Please let me know if you need any more detail on this.
    I think, we have to write subquery in select statement. like,
    Select
    Birth =(select
    STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
    where
    TASK_ID = 136)
    , Death
    =(select
    STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
    where
    TASK_ID = 141)
    , other columns
    From other source tables.
    Thank you in advance.
    Vicky

    >> I have two tables Registration and Place [only one?]. <<
    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. You have been told about this before!! Why do you still behave like this? PLEASE EXPLAIN TO EVERYONE HERE WHY THE MOST BASIC SOCIAL RULES DO NOT APPLY TO YOU??
    >> Please let me know if you need any more detail on this. <<
    WE NEED EVERYTHING! You posted nothing. You do not even know that you should have had “state_code CHAR(2) NOT NULL” in some DDL. You still not know that rows are not records, that tables models sets not single items, etc. 
    Please quit posting until you come up to the level of a total noob who read the forum rules.
    We get tired of doing homework for people who are ignorant, incompetent and rude. 
    --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 make dynamic selection in case of innerjoin

    hi
    in run time i will get some table name into g_v_fubw
    if i write a select quiry like this its working
      SELECT * FROM (g_v_fubw)
        INTO TABLE g_it_fubw
        FOR ALL ENTRIES IN g_it_werks
        WHERE kostl IN s_kostl3    AND
              platznr IN s_platz3  AND
              werks = g_it_werks-werks   AND
              matnr IN s_matnr     AND
              prctr IN s_prctr.
    But if i am  using inner join  like bellow
        SELECT
        avalev ainvpe vastrd vtxjhr a~bukrs
        awerks amatnr
        aindei abwtar a~bklas
        v~adqty
        v~meins
        a~peinh
        INTO TABLE g_it_temp_display
                FROM (g_v_fuba) AS a INNER JOIN
                     (g_v_abcd) AS v ON
                       amatnr = vmatnr AND
                       ainvpe = vinvpe
              WHERE a~invpe EQ p_invw                 AND
                    a~valev EQ 'P'              AND
                    v~astrd IN g_r_astrd              AND
                    v~txjhr IN g_r_txjhr              AND
                    a~bukrs EQ p_bukrs                AND
    its not working
    how can i write dynamic select quiry using innerjoin

    Hi...
    Make sure the structure of g_it_temp_display is same as the selected fields.
    FROM (g_v_fuba AS a INNER JOIN
    g_v_abcd AS v ON
    amatnr = vmatnr AND
    ainvpe = vinvpe ).....>
    See the syntax...
    as below...
    SELECT a~knuma_ag          "SAP agreement number
           a~boart_ag              "SAP agreement type
           a~zzlegsum              "Legacy summary number
           b~datab                 "Begin date
           b~datbi                 "End date
      FROM ( /irm/ipbbasp AS a INNER JOIN  kona AS b ON
      aknuma_ag = bknuma )
      INTO TABLE i_irm_kona
      FOR ALL ENTRIES  IN i_kona_deal
      WHERE a~boart_ag IN r_agrmnt_typ  AND         "SAP agreement type
            a~zzlegsum IN r_summ_number AND         "Legacy summary number
            b~knuma = i_kona_deal-knuma AND         "SAP agreement No
            b~valdt    IN r_ppd.                "Prior price date

  • Select where case

    I am trying to build the query below to throw in SSRS.  I have a multivalued parameter called @category.  When the value of
    USCATVLS_2 is blank I want to still have the option to pull it in my report.  Below is what I have started that doesn't work.  any ideas?
    select
    *fromiv00101
    i
    where
    i.USCATVLS_2
    =(casewheni.uscatvls_2
    =''then'NA'elsein(@category)end)
    http://www.isolutionspartners.com/

    My parameter is multivalue, so it should look something like the syntax below, but the syntax doesn't check out.  Any ideas?
    select
    *fromiv00101
    i
    where
    i.uscatvls_2
    =CASEWHENi.uscatvls_2
    =''THEN'NA'ELSEin(@category)END
    http://www.isolutionspartners.com/

  • How to know which radiobutton is selected in case of dynamic UI generation and how to pass it to back end?

    This is how I have written for dynamically generating radiobuttons. I have some categories on left view, by selecting which, i will get corresponding questions and it generates 5 options, and user selects one and I need to pass it to back end. I am using IModifiableSimpleValueSet for filling the radiobuttons.
    ISimpleTypeModifiable myType = wdThis.wdGetAPI().getContext().getModifiableTypeOf("Ans.option");
      IModifiableSimpleValueSet values = myType.getSVServices().getModifiableSimpleValueSet();
    values.put(d,wdContext.nodeAns().getElementAt(d).getAttributeValue("option").toString());
    Kindly help, if I am missing something.
      IWDRadioButtonGroupByKey radioKey = (IWDRadioButtonGroupByKey)view.createElement(IWDRadioButtonGroupByKey.class,           "ansRadio"+radio_count++);
      IWDMatrixHeadData matrixHead_radio = (IWDMatrixHeadData)radioKey.createLayoutData(IWDMatrixHeadData.class); 
      IWDAction radioAction = wdThis.wdCreateAction(IPrivateRightView.WDActionEventHandler.SELECT_ANS, radioKey.getId());
      wdComponentAPI.getMessageManager().reportSuccess("radio id"+radio_count);
      radioKey.bindSelectedKey("Ans.option");
      radioKey.mappingOfOnSelect().setString("optionID", radioKey.getSelectedKey());
      wdContext.currentContextElement().setSel_ans(wdContext.currentAnsElement().getOption());
      radioKey.setColCount(1);
      questContainer.addChild(radioKey);

    Hi Jun,
    I have to prepare a questionnaire. Some set of questions will be there in backend having 5 options. Based on category I have to fetch questions and its corresponding answers. Ans is the node which I am filling with choices, based on questions.

  • 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 help

    use 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

Maybe you are looking for

  • No table entries found for specified key

    Hi All, I have developed a program to upload data from flat file with the help of GUI UPLOAD. It is succesfully updating data in my Z-table. Whenever I tried to view the content of table for specific field, message shows No table entries found for sp

  • How to enable a table cell dynamically?

    Hi I have a javafx TableView with editable and non-editable columns. I have set editable columns CellFactory to a custom EditableTextCell.This makes the whole column editable on load of the Scene. I have one more requirement for the same table. I hav

  • Document could not be printed

    Unable to print numerous different PDFs from a corporate website. Each file has similar header, images, length, appearance. Opening the files online I receive the message "Insufficient data for an image" but the images do appear after I scroll down a

  • Same XML content on more than one page?

    (Indesign CC on OSX) I have a  12-page indesign document in which each page contains a resized version of the same ad. (for placment in a variety of publications) I have an external xml file that contains master copy. When I link to this file, the co

  • Asset & Capital Expenditure Budgeting

    Hi I am struck in Asset Purchases and Budgeting. We want to monitor & COntrol the Cpital Expenditure ( Assets). There for I tried to use the Internal orders to control the assets being purchased more than the budget value. The process is as follwos.