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

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

  • SQL CASE statement in XML template- End tag does not match start tag 'group

    Hi All,
    I am developing a report that has the SQL CASE statement in the query. I am trying to load this into RTF with report wizard and it gives me below error
    oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'group'
    Does XML publisher support CASE statement?
    My query is something like this
    SELECT customercode,
    SUM(CASE WHEN invoicedate >= current date - 30 days
    THEN balanceforward ELSE 0 END) AS "0-30",
    SUM(CASE WHEN invoicedate BETWEEN current date - 60 days
    AND current date - 31 days
    THEN balanceforward ELSE 0 END) AS "31-60",
    SUM(CASE WHEN invoicedate < current date - 60 days
    THEN balanceforward ELSE 0 END) AS "61>",
    SUM(balanceforward) AS total_outstanding
    FROM MyTable
    GROUP BY customercode
    ORDER BY total_outstanding DESC
    Please advice if the CASE statement or the double quotes are causing this error
    Thanks,
    PP

    I got this to work in the XML but the data is returning zeros for all the case statements. When I run this in toad I get results for all the case conditions but when ran in XML the data displayed is all zeros. I am not sure what I am missing. Can someone shed some light on this please
    Thanks!
    PP

  • 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

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

  • PL/SQL - Case Statement

    Hello, just starting to learn PL/SQL. I have a query which runs just fine and it has a case statement. When I take that query and place it into a procedure and compile, it gives me a compile error stating "ENCOUNTERED symbol CASE when expecting... providing a list of symbols.
    This procedure is part of a package, so I am only showing the procedure portion...
    PROCEDURE QRY_USERS (oRows                     OUT t_cursor)
    IS
    BEGIN
         OPEN o_Rows FOR
         select ou.User_id,
                   ou.AD_Login_ID,
                   ou.First_name,
                   ou.Last_Name,
         oct.CODE_DESC,
                   case when ou.deleted is null then 'N'
                   else 'Y' end Deleted
         from tst_ops_users ou, tst_ops_code_tbl oct
         where oct.CODE_TYPE ='USER_TYPE'
              and oct.code_name = ou.USER_ROLE_TYPE;
    END QRY_USERS;
    So is there some different syntax with case statements or is there some other erro causing this?
    Thanks a bunch for your assistance!!!

    Which version of the database are you working on? In 8i the PL/SQL engine did not support the use of CASE in SQL statements (along with a whole bunch of other fresh additions to SQL syntax).
    If that is your problem you could try this, which ought to use the SQL engine instead...
    PROCEDURE QRY_USERS (oRows OUT t_cursor)
    IS
    BEGIN
    OPEN oRows FOR
    'select ou.User_id,
    ou.AD_Login_ID,
    ou.First_name,
    ou.Last_Name,
    oct.CODE_DESC,
    case when ou.deleted is null then ''N''
    else ''Y'' end Deleted
    from tst_ops_users ou, tst_ops_code_tbl oct
    where oct.CODE_TYPE =''USER_TYPE''
    and oct.code_name = ou.USER_ROLE_TYPE';
    END QRY_USERS;although you can obviate the need for CASE by using either DECODE or NVL2...
    nvl2(ou.deleted , 'Y', 'N') AS deletedCheers, APC

  • SQL Case Statement

    Hi,
    could you please advise how to add below New case to below Main case
    New case:
    when (convert(varchar,date,101) >= '01/01/2014' OR qtr >= '14Q1') then
    case when PP='ABC' and pl='EFG' then Revenue*.552
    else 0 end
    Main case:
    SUM(
    case
    when ((convert(varchar,date,101)>= '09/19/2013' and qtr = '13Q3') OR qtr >= '13Q4') then
    case when PP='ABC' and pl='EFG' then Revenue*.542
    else 0 end
    when (convert(varchar,date,101) < '09/19/2013' OR qtr < '13Q3') then
    case when PP='ABC' and pl='EFG' then Revenue*.501
    else 0 end
    else 0 end) revenue,

    There is no CASE statement in SQL; we have CASE expression. AND you got the syntax wrong. SQL uses the ISO-8601 date format; it is one of the most basic ISO Standards on Earth AND you should know it. But worse than that, you are still using the 1970's
    Sybase CONVERT string function! NO! Did you know that DATE is a reserved word in SQL AND cannot be a column name? 
    When we design a code for temporal units like Quarters, we follow the ISO-8601 as closely as possible. That means a full four-digit year. 
    Since you were rude AND did post DDL, I will guess that your improper “date” is a TIMESTAMP (aka DATETIME or DATETIME2(n) in Microsoft dialect). 
    >> could you please advise how to add below New CASE to below Main CASE <<
    I never heard the term “main CASE”, even when I voted on this feature. Can you explain it to me and show where I missed it? 
    The quarters are temporal computations; we would not put them in a base table, but a good SQL programmer would use a VIEW with a join to a report period table.   
    CASE WHEN CAST (foobar_timestamp AS DATE) >= '2014-01-01'
           OR foobar_qtr > = '2014Q1'
         THEN CASE WHEN pp = 'ABC' 
                   AND pl = 'EFG'
              THEN something_revenue * 0.552
              ELSE 0.000 END;
    I will assume that pl and pp well-understood terms in your industry and not improper data element names. Why did you nest CASE expressions? Let me answer that: you think that CASE is IF-THEN-ELSE statements! 
    Did you notice that an event during '2014Q1' is always BETWEEN '2014-01-01' AND '2014-03-31'? So this is redundant! 
    A minor point, it is good idea to use a leading zeroes and decimal zeroes to show the guy maintaining code what he is working with. It also helps the compiler avoid casting. Your expression also has no name. 
    CASE WHEN CAST (foobar_timestamp AS DATE) > = '2014-01-01'
     AND pp = 'ABC' 
     AND pl = 'EFG'
     THEN something_revenue * 0.552
     ELSE 0.00 END AS nameless_floob;
    I am afraid that you might have re-discovered the Algol-60 dangling ELSE problem. As with Algol-60, the ELSE in SQL associates with the nearest CASE. Not with the outermost CASE. 
    Your expression ought to have this skeleton: 
    SUM(CASE WHEN ??? 
             THEN something_revenue * 0.542
             WHEN ??? 
             THEN something_revenue * 0.501
             WHEN ???
             THEN something_revenue * 0.552
             ELSE 0.000 END)
     AS something_revenue_tot
    --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

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

  • Can CR 2008 with XML ODBC driver using SQL CASE statement?

    Hi:
    when i use SQL Command to provide data to the report from XML file connection. I can not use CASE statement , CR always has error message about "CASE" word.
    I test the same Statement in SQL client connected to Oracle, it runs fine.
    So.. Is it driver's limitation that XML datasource can not use CASE statement inside SQL command window?
    Thanks anyone's reply in advance.
    Johnnychi

    Hi Johnny,
    CR supports what every the ODBC driver supports. The error you are getting is from the XML driver, CR is just passing it through.
    Try using an ODBC to XML driver and then a stand-alone ODBC test tool to see if your SQL works.
    If not you'll have to find another way to use the CASE statement.
    Thank you
    Don

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

  • Sql case statement with link not opening new window

    Apex 4.2
    I am writing a query that has a case statement. I need the case statement to open up a new window, not a new tab. I have the following:
    SELECT
    case when SCHED_ID = 1 then
    '<a href="javascript:popupURL(''http://www.google.com'')">LINK</a>'
    end as MyLink
    FROM Table_Name
    When I plug this into a a column link in the URL field under a page item or report item, then a popup window appears. However, inside the query I am getting a new tab.
    ANy help on this matter would be great. Thanks in advance.

    Hi,
    Try adding a target attribute to you link:
    '<a href="javascript:popupURL(''http://www.google.com'')" target="_blank">LINK</a>' 
    Regards,
    Vincent

  • Pass ORG_ID as sql statement for parameter in request set

    We are in a multi-org environment. We are running the request PRC: Generate Draft Revenue for a Single Project as part of the request set. We want the request to automatically fill in the open pa period as the accrue through date. We have been using the SQL Statement below as the value for the accrue through date parameter.
    select end_date
    from pa_periods_all
    where status = 'O'
    and current_pa_period_flag = 'Y'
    Unfortunately that does not limit to a specific company. We a company that still have DEC-05 while another has an open period of JAN-06. This is causing the program fits. How do I pass the org_id to the request? [in beginners terms please]
    Thanks.
    Anne

    No idea what might be wroong without more info...
    Do some output. Test the ${params.id} variable passed to the second jsp. If that is correct, then error is in the select statement or display of jsp2. If it is correct the error comes from jsp1.
    If I have to guess, then I would say the error comes from JSP1, and the ${row.vac_id} should only be called once. In which case I would do something like this:
    //in jsp 1
                <c:forEach var="row" items="${results.rows}"  varStatus="counter"  >
                    <c:set var="vac_id" value="${row.vac_id}" scope="page"/>
                    <tr>
                        <td>${vac_id}</td>
                        <td><a href="vacancydetails.jsp?id=${vac_id}">More</a></td>But that is a guess only...
    Errr... Hold on to that as reference, but the it is entirely likely that I misspelled ${params.id} It may be ${param.id} I forget and away from my machine right now...

  • Custom SQL CASE Statement

    Hello All,
    I have a query similar to the one below. I have to use a Custom SQL DB adapter to achieve this. When i create a variable I get four variables in the input payload (two for Param1 and two for Input). I was wondering if we can avoid this, because this is like duplicity and we have to populate the values twice each (I know this can be achieved by a Procedure, but we have a restriction).
    SELECT CASE
    WHEN #param1 = 'P1'
    THEN (SELECT col1
    FROM table1
    WHERE col2 = #input)
    END column1,
    CASE
    WHEN #param1 = 'P2'
    THEN (SELECT col1
    FROM table2
    WHERE col2 = #input)
    END column2,
    FROM DUAL;
    The input collection is as shown below.
    <xs:complexType name="compiste_queryInput">
    <xs:sequence>
    <xs:element name="param1" type="xs:string" nillable="true"/>
    <xs:element name="input" type="xs:string" nillable="true"/>
    <xs:element name="param1" type="xs:string" nillable="true"/>
    <xs:element name="input" type="xs:string" nillable="true"/>
    </xs:sequence>
    </xs:complexType>
    Any help is much appreciated.
    Thanks
    Krishna

    Hi Krishna,
    I think this is a limitation. Actually it creates an element in xsd for each bind parameter and won't allow having 2 elements with the same name inside the xsd.
    The one given by you also will report a compile time error as it is using #param1 and #input twice.
    You need to change them to param1, param2 etc. and copy the same values to each.
    Appreciate if anyone can post a workaround for the same.
    Regards,
    Neeraj Sehgal

  • SQL CASE STATEMENT IMPLEMENTATION

    REquirment
    • Add indicator to the end of the files, (position 1051 in both extracts, either have value of Y or N).
    o DUAL COVERAGE (Y/N)
    • Logic to determine indicator values from Member Eligibility Table:
    o For ‘Y’ indicator:
    o When dbo. CMC_MEPE_PRCS_ELIG.CSCS_ID = ‘MD11’ (Mean Dual covered member)
    o For ‘N’ indicator:
     When dbo. CMC_MEPE_PRCS_ELIG.CSCS_ID <> ‘MD11’
    • Groups included:
    o 100100 (Medicare)
    o 100598 (Medicaid-OHP)
    • Previous syntax
    • select top 20000
    • EXT_DATE,SUPPLIER_NAME,BUSINESS_UNIT,PROG_NO,PG_DESC,DIVISION_NO,RISKPOP_MEDICARE_EVENT_CODE,
    • RISKPOP_MEDICAID_AID_CATEGORY,MEMBER_NO,MEDICARE_NO,MEDICAID_NO,LASTNAME,MIDINITIAL,FIRSTNAME,YMDBIRTH,
    • a.SEX,CLASS,CL_DESC,S_LASTNAME,S_MIDINITIAL,S_FIRSTNAME,S_DOB,S_SEX,BENFIT_PKG,BEN_PKG_DESC,CLASS_ID,PLAN_ID,
    • YMDEFF_BP,YMDEND,REASON,PRIME_SECOND,PHP_DUAL,S_ADDRESS1,S_ADDRESS2,S_ADDRESS3,S_CITY,S_STATE,S_ZIP,S_COUNTRY,
    • S_PHONE,M_ADDRESS1,M_ADDRESS2,M_ADDRESS3,M_CITY,M_STATE,M_ZIP,M_COUNTRY,M_PHONE,DIV_NAME,PROV_NO,IRS_NO,
    • P_LASTNAME,P_FIRSTNAME,P_MIDINITIAL,YMDEFF_PCP,ALT_KEY,ALT_CARRIER_NO,ALT_CARRIER_FUL,ALT_YMDEFF,ALT_YMDEND,
    • BENFIT_PKG_EFF,BENFIT_PKG_TERM,a.MEME_CK,
    • b.HIOS_NUMBER,
    • null as PREMIUM_PAID_DATE,
    • null as PREMIUM_PAID_END_DATE,
    • b.APTC,
    • null as 'GracePeriodIndicatorStartDate',
    • null as'GracePeriodIndicatorEndDate',
    • null as'ExchangePlanType'
    • from Extract_602_603_PBH_Extract_Main a
    • left join Extract_602_603_PBH_Extract_HRI b
    • on LEFT(a.MEMBER_NO,7) = b.SBSB_ID
    Syntax I am trying to implement(taking forever to execute) Please help correct
    select distinct
    EXT_DATE,SUPPLIER_NAME,BUSINESS_UNIT,PROG_NO,PG_DESC,DIVISION_NO,RISKPOP_MEDICARE_EVENT_CODE,
    RISKPOP_MEDICAID_AID_CATEGORY,MEMBER_NO,MEDICARE_NO,MEDICAID_NO,LASTNAME,MIDINITIAL,FIRSTNAME,YMDBIRTH,
    a.SEX,CLASS,CL_DESC,S_LASTNAME,S_MIDINITIAL,S_FIRSTNAME,S_DOB,S_SEX,BENFIT_PKG,BEN_PKG_DESC,CLASS_ID,PLAN_ID,
    YMDEFF_BP,YMDEND,REASON,PRIME_SECOND,PHP_DUAL,S_ADDRESS1,S_ADDRESS2,S_ADDRESS3,S_CITY,S_STATE,S_ZIP,S_COUNTRY,
    S_PHONE,M_ADDRESS1,M_ADDRESS2,M_ADDRESS3,M_CITY,M_STATE,M_ZIP,M_COUNTRY,M_PHONE,DIV_NAME,PROV_NO,IRS_NO,
    P_LASTNAME,P_FIRSTNAME,P_MIDINITIAL,YMDEFF_PCP,ALT_KEY,ALT_CARRIER_NO,ALT_CARRIER_FUL,ALT_YMDEFF,ALT_YMDEND,
    BENFIT_PKG_EFF,BENFIT_PKG_TERM,a.MEME_CK,
    b.HIOS_NUMBER,
    null as PREMIUM_PAID_DATE,
    null as PREMIUM_PAID_END_DATE,
    b.APTC,
    null as 'GracePeriodIndicatorStartDate',
    null as'GracePeriodIndicatorEndDate',
    null as'ExchangePlanType',
    case when MEPE.CSCS_ID = 'MD11' AND grgr.GRGR_ID IN('100100','100598')
    THEN 'Y'
    ELSE 'N' end as DualCoverageIndicator
    from Extract_602_603_PBH_Extract_Main a
    left join Extract_602_603_PBH_Extract_HRI b
    on LEFT(a.MEMBER_NO,7) = b.SBSB_ID
    join FacetsReport.dbo.CMC_MEPE_PRCS_ELIG MEPE
    ON a.CLASS_ID= MEPE.CSCS_ID
    Join FacetsReport.dbo.CMC_GRGR_GROUP grgr
    ON MEPE.GRGR_CK= grgr.GRGR_CK

    >on LEFT(a.MEMBER_NO,7)
    =b.SBSB_ID
    This is not a good JOIN. It is not SARGable:
    http://www.sqlusa.com/bestpractices/sargable/
    Can you post table/index DDL? Thanks.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

Maybe you are looking for

  • Can I use SSRT as a QOS metric?

    I'm wondering if I can use SSRT as a good metric for how good the P2P link is between two video chat clients.  I did the following experiment. First I connect two of our clients together in a video chat. Then I start logging the netstreamInfo from my

  • MPN in source list

    Hi experts! I put a specific MPN in the source list as fixed. Then when I make the PO, the system allows me to introduce another MPN, not the one that I specifically inform in the source list. Does anyone know how to solve this problem? Thanks, Marí

  • Anyone using 7.0.98.0 with any BIG problems?

    I have 7.0.98.0 burning in at one of our locations with 8 WiSMs and 500+ clients for about 6 weeks now. We haven't had any big issues and are looking to move forward with another side deployment and eventually a campus wide deployment which consist o

  • Reduce opacity of gridlines in lens correction

    Is it just me or are the gridlines whiter in the manual lens corrrection? Can you make them feinter in any way?

  • Is there anyway to take a song and use only part of it?

    I need to use the intro and solos from a few songs is there anyway to do that?