CASE Statement for Multiple Criteria

Hello,
I need to write a query that will give me a count of customers that fall in three different categories:
< 1 year
1 to 3 years
3 yearsI have written the code to bring me back the 1st set of criteria (< 1 yr). I am using the date connected to a customer's account(s) to return the oldest date attached to an account to put that customer in the appropriate bucket. Below is the code I have for the first piece:
SELECT COUNT(*) AS One_Year_Or_Less
FROM
(SELECT c.lname||', '||c.fname AS Name, MIN(a.contractdate) AS ContractDate
FROM account a, customer c
WHERE a.custnbr = c.custnbr
GROUP BY c.lname, c.fname) yr
WHERE yr.contractdate BETWEEN TO_DATE('03/02/2005', 'MM/DD/YYYY')
AND SYSDATE
The above query runs and returns what I beleive to be an accurate count of customers who fall in the 1 year or less range. My question is; how can I add the criteria of 1 to 3 years and > 3 years to this query. I need to have 3 seperate columns (or 3 seperate rows) that contain the heading of the specific criteria and then the count for that criteria. I was thinking of trying to use a CASE statement but I am unsure of exactly how to do that. Perhaps I could somehow create 3 seperate sub-queries to acheive my goal. Any help with this issue will be greatly appreciated. Thank you.
Dave Y

Here's another way. It will only count those that meet the criteria, otherwise it will sum a 0. If you just want 1 row returned with the counts, there's no need for a GROUP BY
SELECT SUM(CASE
               WHEN contractdate >  add_months(sysdate,-12) THEN 1
               ELSE 0
           END) less_than_1_year
      ,SUM(CASE
               WHEN contractdate >= add_months(sysdate,-36)
               AND  contractdate <= add_months(sysdate,-12) THEN 1
               ELSE 0
           END) from_1_to_3_years
      ,SUM(CASE
               WHEN contractdate <  add_months(sysdate,-36) THEN 1
               ELSE 0
           END) over_3_years
FROM ...

Similar Messages

  • 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

    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= 10

    What 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

  • Help With A Case Statement With Multiple Variables

    I apologize if this is the incorrect Forum for this type of question, but it was the closest one that I could find. I'm pretty new with SQL and am stuck on this issue. I have roughly 26 dates that I need to compare to one another. Each date is tied to a step code. I also have a Stop value that is tied directly to the "max date" of the step codes. So, I need to compare 30 dates against one another to 1st - ID the max date; 2nd - ID if the Stop value is correct; 3rd - if the stop value is incorrect, identify what the correct value would be.
    At first, this seemed like it wouldn't be that hard. I wrote a query that found the max date for each step code. Then I realized that multiple step codes could have the same date. So, I tried using this case statement, but I did not get the expected results. Is there a more efficient way of getting what I need? This code seems like it's not necessary and probably the source of my issue.
    CASE
    WHEN FS25.ACTUAL_COMPLETION_DATE > FS.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS1.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS2.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS3.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS4.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS5.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS6.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS7.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS8.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS9.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS10.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS11.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS12.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS13.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS14.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS15.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS16.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS17.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS18.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS19.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS20.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS21.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS22.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS23.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS24.ACTUAL_COMPLETION_DATE AND L.FORECLOSURE_STOP_CODE <= '8' THEN '9'
    ELSE 'UH OH'
    END AS "CHANGE FC STOP TO"
    Any assistance is appreciated!

    I think Igor pointed out a working solution before.
    Applying it at your examples (you missed the operator after STOP_CODE, I assume it =):
    CASE
    WHEN FS25 = GREATEST(FS25, FS24, FS23) AND STOP_CODE = '9' THEN '9'
    ELSE 'UH OH'
    END AS 'CHANGE STOP CODE TO'
    {code}
    Be careful at the second example. You are checking:
    {code:sql}
    FS25 > FS24 OR FS25 IS NOT NULL AND FS24 IS NULL AND FS25 > FS23
    OR
    FS25 IS NOT NULL AND FS23 IS NULL AND STOP_CODE = '9'
    {code}
    Remember that AND has higher priority among operators than OR so if FS25 is greater than FS24 and FS23 the condition will be true even if STOP_CODE is not equal 9.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Enforcement States for multiple deployment ID's

    I would like to have a report for the enforcement states of multiple deployment ID's. I have tried manipulating the default "States 1 - Enforcement states for a deployment" to have multiple default values but have not succeeded in getting
    the report to run.
    In our Software Updates we have multiple collections targeting specific groups of computers and then we have specific update groups within specific date ranges deployed to those collections. In some cases I have multiple deployments targeting the same collection
    and thus the want to have a single report for the enforcement status of multiple deployment ID's.
    Unfortunatley my level of SQL reporting is minimal, does anyone have knowledge of a report or query to use multiple deployment ID's for returning the enforcement states?

    Hi,
    You may have a look on the following blog, hope this could help you edit your report.
    http://blogs.msdn.com/b/steverac/archive/2013/01/13/modifying-a-report-to-merge-software-update-deployments-with-updates-delivered-through-standard-software-distribution.aspx
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Use of LIKE in where clause of select statement for multiple records

    Hi Experts,
    I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
    For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
    And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
    data : begin of t_dda occurs 0,
            dda(19) type c,
           end of t_dda.
    data : begin of t_bukrs occurs 0,
            bukrs type t012k-bukrs,
           end of t_bukrs.
    data : dda type t012k-bankn,
           w_dda type t012k-bankn.
    CONCATENATE '%'
                             '2ARS1'
                     INTO  W_DDA.
    MOVE W_DDA TO T_DDA-DDA.
    APPEND T_DDA.
    CLEAR T_DDA.
    free t_bukrs.
    SELECT BUKRS
      FROM T012K
      into TABLE t_bukrs
        for all entries in t_dda
    WHERE BANKN like t_dda-dda.
    Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
    Thanks in advance,
    Akash

    Hi,
    yes, For All entries won't work for LIKE with '%  '.
    I think the other alternative is go for Native SQL by writing sub-query
    sample code is here:
    data: begin of i_mara occurs 0,
              matnr like mara-matnr,
              matkl like mara-matkl,
           end of i_mara.
    exec sql.
    select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
    endexec.
    loop at i_mara.
    write:/ i_mara-matnr, i_mara-matkl.
    endloop.
    hope u got it.
    regards
    Mahesh
    Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM

  • Case statement for dashboard text title based on NQ_SESSION.ROLES

    Hello,
    I figured out on my dashboard I can add a textbox
    with the code '@{biserver.variables['NQ_SESSION.ROLES']}'  and it shows the user groups. That works great. Now
    I need to have a case statement or so that shows a text, that changes
    with each user role i.e. each user role gets its own "report title" Is that possible?
    Thanks.

    Hello,
    Thanks for the column formula example.
    Unfortunately in both cases it resolves to the ELSE clause even when the other two are true:
    case  when Locate('BIConsumer_Two', VALUEOF(NQ_SESSION.ROLES))>0 then @{VAR_REPORTTITLE}{'test'} when Locate('BIConsumer_One', VALUEOF(NQ_SESSION.ROLES))>0 then @{VAR_REPORTTITLE}{'test2'}   else @{VAR_REPORTTITLE}{'test3'}   end  
    case when Position('userrole1' in VALUEOF(NQ_SESSION.ROLES))>0 then 'w00t' else 'ang' end
    The one below works (at least I can read test1 on the results page of my answers report:
    case when Position('mytestrole' in 'mytestrole')>0 then @{VAR_REPORTTITLE}{'test1'} else @{VAR_REPORTTITLE}{'test'} end
    The NQ_SESSION.ROLES comes like this:
    'BIConsumer_One;BIAdministrator;AuthenticatedUser;BIConsumer;BIConsumer_Two;BIAuthor'
    I realized why I could not resolve it. I did not define it as a session but presentation variable. So here it is a session variable:
    case when Position('mytestrole' in 'mytestrole')>0 then VALUEOF(NQ_SESSION.VAR_REPORTTITLE) ='test1' else VALUEOF(NQ_SESSION.VAR_REPORTTITLE)='test2' end
    but now there is an error: [nQSError: 26012]

  • Case statement for States

    Hi All,
    I am trying to populate a text field based on what the user chooses in a drop down that contains the 50 United States of America.
    So...let's say for now that I want the text field to say "Birmingham" if the user chooses "Alabama".
    The only thing I have so far is totally wrong:
    function setText()
    var statechoice = State.value;
    switch (statechoice) {
    case 1:
    Text1.rawValue = "Filing is required in Alabama";
    break
    case 2:
    Text1.rawValue = "Very cold and Filing is required in Alaska";
    break
    default:
    Text1.rawValue = "Choose a state please";
    break
    Does it always have to be case 1, 2, 3 and so on? Can't it ever be "case (something is true and something equals 7):"?  I mean, do I always have to use integers to distinguish the cases?
    later on, I want to populate that drop down based on several choices that the user makes. I want to have a list of conditionals where each conditional expresses a unique combination of choices that the user has made.
    Do you like cold food? Yes
    Lactose intolerant? No
    Text Field says "Have an ice cream cone for dessert".
    How do I get integer values from a drop down? dropdown.value? dropdown.index? dropdown.selectedIndex?
    How do I combine these choices in the case statements? case (dd1 = 1 and dd2 = 4 and dd3 = 2):   ???
    Sorry for this discursive question,
    I just need a good code example to follow.
    Many Thanks,
    Joe

    Few things to mention.
    1) You can get the selected value from the dropdown by using rawValue property.. But in your code you have used "State.value"..It should be "State.rawValue"..
    2) In the Case statement:
           case 1/2/3 etc.. are values of the selected value from the State dropdown. If you assign "AL" for Alabama, then you need to use "case "AL":"
    function setText()
    var statechoice = State.rawValue;
    switch (statechoice) {
    case "AL":
    Text1.rawValue = "Filing is required in Alabama";
    break;
    case "AK":
    Text1.rawValue = "Very cold and Filing is required in Alaska";
    break;
    default:
    Text1.rawValue = "Choose a state please";
    break;
    Find my changes to your script above..
    Thanks
    Srini

  • Case statement for interactive report error

    The case computation does not work for me :
    statement
    CASE WHEN G = 7 THEN G ELSE C END
    Error message ' Invalid computation expression. THEN'
    It does not seem to matter what the case statement is IE :
    CASE WHEN I = 'DEMO' THEN 'LOW' ELSE 'HIGH' END
    I have tried this on the Sample Application that is installed on my oracle workspace account
    Column G : order number ( number)
    Column C:order total (Number)
    Column I:sales Rep ( String)
    Can someone please tell me what I am doing wrong ?
    Thanks

    Your statement works for me exactly as you typed it:
    SQL> select * from t;
                       G                    C
                       1                  101
                       2                  102
                       3                  103
                       4                  104
                       5                  105
                       6                  106
                       7                  107
    7 rows selected.
    SQL> select CASE WHEN G = 7 THEN G ELSE C END
      2  from   t;
    CASEWHENG=7THENGELSECEND
                         101
                         102
                         103
                         104
                         105
                         106
                           7
    7 rows selected.

  • Manual Bank Reconciliation Statement for multiple dates

    How can we enter ONE manual BRS for multiple posting dates?
    Below is the scenario for which we need multiple posting dates in one bank statement.
    We receive and enter in SAP the Bank reconciliation statement at the end of every month.  The system considers Posting date as end of the month ( the entry date or a single date what we enter).  The transactions however belongs to many dates of the month.  So while posting the bank statement system considers only one posting date and picks up the exchange rates of one date ( that is the posting date).  It results in undesired exchange rate differences.
    To elaborate more please check the following example:
    1. Incoming Payment on 01-12-09 in USD (USD = Foreign Currency, AED = Local Currency ) with Exchage rate 3.8.
    2. Incoming Payment on 06-12-09 in USD with Exchange rate 3.9
    3. Incoming Payment on 09-1209 in USD with Exchange Rate 3.7
    If all of the above transactions are posted at one posting date the system picks up only one exchange rate at the posting date.  However the system should pick up the respective exchange rates on the transaction date.
    I hope I am able to communicate properly.
    Waiting for your expert opinion forks.
    Amir

    How can we enter ONE manual BRS for multiple posting dates?
    Below is the scenario for which we need multiple posting dates in one bank statement.
    We receive and enter in SAP the Bank reconciliation statement at the end of every month.  The system considers Posting date as end of the month ( the entry date or a single date what we enter).  The transactions however belongs to many dates of the month.  So while posting the bank statement system considers only one posting date and picks up the exchange rates of one date ( that is the posting date).  It results in undesired exchange rate differences.
    To elaborate more please check the following example:
    1. Incoming Payment on 01-12-09 in USD (USD = Foreign Currency, AED = Local Currency ) with Exchage rate 3.8.
    2. Incoming Payment on 06-12-09 in USD with Exchange rate 3.9
    3. Incoming Payment on 09-1209 in USD with Exchange Rate 3.7
    If all of the above transactions are posted at one posting date the system picks up only one exchange rate at the posting date.  However the system should pick up the respective exchange rates on the transaction date.
    I hope I am able to communicate properly.
    Waiting for your expert opinion forks.
    Amir

  • Scheduled Job to gather stats for multiple tables - Oracle 11.2.0.1.0

    Hi,
    My Oracle DB Version is:
    BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    In our application, we have users uploading files resulting in insert of records into a table. file could contain records ranging from 10000 to 1 million records.
    I have written a procedure to bulk insert these records into this table using limit clause. After the insert, i noticed my queries run slow against these tables if huge files are uploaded simultaneously. After gathering stats, the cost reduces and the queries executed faster.
    We have 2 such tables which grow based on user file uploads. I would like to schedule a job to gather stats during a non peak hour apart from the nightly automated oracle job for these two tables.
    Is there a better way to do this?
    I plan to execute the below procedure as a scheduled job using DBMS_SCHEDULER.
    --Procedure
    create or replace
    PROCEDURE p_manual_gather_table_stats AS
    TYPE ttab
    IS
        TABLE OF VARCHAR2(30) INDEX BY PLS_INTEGER;
        ltab ttab;
    BEGIN
        ltab(1) := 'TAB1';
        ltab(2) := 'TAB2';
        FOR i IN ltab.first .. ltab.last
        LOOP
            dbms_stats.gather_table_stats(ownname => USER, tabname => ltab(i) , estimate_percent => dbms_stats.auto_sample_size,
            method_opt => 'for all indexed columns size auto', degree =>
            dbms_stats.auto_degree ,CASCADE => TRUE );
        END LOOP;
    END p_manual_gather_table_stats;
    --Scheduled Job
    BEGIN
        -- Job defined entirely by the CREATE JOB procedure.
        DBMS_SCHEDULER.create_job ( job_name => 'MANUAL_GATHER_TABLE_STATS',
        job_type => 'PLSQL_BLOCK',
        job_action => 'BEGIN p_manual_gather_table_stats; END;',
        start_date => SYSTIMESTAMP,
        repeat_interval => 'FREQ=DAILY; BYHOUR=12;BYMINUTE=45;BYSECOND=0',
        end_date => NULL,
        enabled => TRUE,
        comments => 'Job to manually gather stats for tables: TAB1,TAB2. Runs at 12:45 Daily.');
    END;Thanks,
    Somiya

    The question was, is there a better way, and you partly answered it.
    Somiya, you have to be sure the queries have appropriate statistics when the queries are being run. In addition, if the queries are being run while data is being loaded, that is going to slow things down regardless, for several possible reasons, such as resource contention, inappropriate statistics, and having to maintain a read consistent view for each query.
    The default collection job decides for each table based on changes it perceives in the data. You probably don't want the default collection job to deal with those tables. You probably do want to do what Dan suggested with the statistics. But it's hard to tell from your description. Is the data volume and distribution volatile? You surely want representative statistics available when each query is started. You may want to use all the plan stability features available to tell the optimizer to do the right thing (see for example http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/ ). You may want to just give up and use dynamic sampling, I don't know, entire books, blogs and papers have been written on the subject. It's sufficiently advanced technology to appear as magic.

  • Update statement for multiple records

    i have table a and table b
    common col in both the tables is emp_id
    in table b i have district_id
    which i want to update in table a.... column district_id for all the employees
    how to write update statement for this
    Edited by: user10873676 on Oct 17, 2011 8:00 AM

    Based on your current description, we have something like this...
    SQL> create table a (emp_id number)
      2  /
    Table created.
    SQL>
    SQL> create table b (emp_id number, district_id number)
      2  /
    Table created.
    SQL>
    SQL> insert into a (emp_id)
      2  select rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> insert into b (emp_id, district_id)
      2  select rownum, 10-rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> update b
      2  set district_id = 1
      3  /
    10 rows updated.
    SQL>
    SQL> select * from a;
        EMP_ID
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL> select * from b;
        EMP_ID DISTRICT_ID
             1           1
             2           1
             3           1
             4           1
             5           1
             6           1
             7           1
             8           1
             9           1
            10           1
    10 rows selected.Which I'm sure is NOT what you want as the update on table b has nothing to do with table a, and we have no idea what the district_id should be updated with.

  • Manual Bank Statement for multiple Currencies

    Hi All
    I need to configure the manual bank statement for FF67 to hit 2 different accounts based on the Currency.
    For example - if I give my rules in customizing - to pick account that ends with a +++++++++30 for foreign currency and again specify a rule to pick accounts that end with ++++++++80 for EUR. It always picks the first account on the rule.
    And on my account symbol assignment to Account step - I am sepcifying the currency for the EUR.
    I have Posting Rule 22 defined for Foreign currencies and a Posting Rule 22w defined for EUR postings - but it never picks the 22w.
    Is there anyway to make this work?
    Thanks much!
    RS

    This is not possible.
    See your FI12, for every house bank and account ID, you have given transaction currency.
    Therefore, that particular house bank and account can transact in only that currency.
    For the same account, you cannot post in two different currencies.

  • How to implement Case Structure for multiple inputs to Pic Ring?

    So I have a reasonably simple program which I am almost completeed with. Basically the data of an array is read and then is indexed and a new array is created from the indexed data. And then I use Match Pattern to see if elements in the new array match certain words. And if they do then a number value is allocated to a Pic Ring at the end. And depending on the final number value the Pic Ring changes from one pic to another.
    However, I have the problem that I will be using multiple Match Pattern functions to compare elements in the final array, but I can't attach multiple Match Patterns and their subsequent logic statements to a single Pic Ring, only one. I've been trying to work this out by implementing a Case Structure or Event Structure. But the Event Structure isn't working and with the Case Structure, it is very messy with multiple True/False Case Structures inside of each other. Anyway, hopefully this all makes some sense. I'm attaching the VI program to this post. Thanks.
    Attachments:
    ArrayTest2.vi ‏495 KB
    ArrayTest2.vi ‏495 KB

    Obviously, you can only display one picture.  So then the question becomes which picture to show.  Therefore, you will have to create some sort of preference of one pattern over another.
    I would use a FOR loop so that you can loop through your available patters and their possible results.  Use the Conditional Terminal on the FOR loop so that you can stop the loop on the first match.  Then you just wire up the selected value for the ring outside of the loop.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Sql case statement for parametes

    I am using sort parameters in the stored procedure
    the following is my case statment
    CASE When @SORT_1 = 'CUSTOMER'
                     Then ar_ivhdr_tbl.EN_CUST_KEY
                     When @SORT_1 = 'BILLTO'
                    Then ar_bill_tbl.ar_bill_name
                     Else ' ' END SORTKEY
    what i would like to do is
    have the sort key sort by 2 fields so instead of just the customer sort sorting the customer field
    i would like it to sort customer and bill to
    this is the syntax i tried but sql doesnt like it
    CASE When @SORT_1 = 'CUSTOMER'
    Then ar_ivhdr_tbl.EN_CUST_KEY,ar_bill_tbl.ar_bill_key
    When @SORT_1 = 'BILLTO'
    Then ar_bill_tbl.ar_bill_name, date
    Else ' ' END SORTKEY
    syntax issues, any ideas?

    Hi Sharon,
    Your syntax is off.  Not sure what database you are using by it should look something like:
    CASE @SORT_1
    When 'CUSTOMER' Then ar_ivhdr_tbl.EN_CUST_KEY,ar_bill_tbl.ar_bill_key
    When 'BILLTO' Then ar_bill_tbl.ar_bill_name, date
    Else ' '
    END
    Good luck,
    Brian

  • Random selections for multiple criteria

    I think the easiest way to explain my question would be to use an example.  Lets say I have 10,000 sales reps and I want a random sampling of 10% of them.  I create a formula {@Random}: Rnd(), use that formula to sort, and suppress the details where recordnumber > 1000.  I got that.
    Now lets say those reps are divided into club levels where there are 500 top performers, 2500 in the next group, and 7000 in the last.
    ( {contact.Club} = A )
    ( {contact.Club} = B)
    ( {contact.Club} = C)
    I only want a random 10% from each category, so 50, 250, and 700 respectively.  Does anyone know how I could get that to work?
    The following thread seems similar but I wasn't able to follow or did something wrong.
    Re: Random and Grouping Problem

    Please re-post if this is still an issue or purchase a case and have a dedicated support engineer work with you directly

Maybe you are looking for