SQL to get previos quarter

Hi,
what will be the SQL to get previos quartert from SYSDATE
Thanks
V

Hi,
Here's one way:
SELECT     TO_CHAR ( TRUNC (SYSDATE, 'Q') - 1
          , 'YYYY-Q'
          )          AS prev_qtr
FROM    dual
;The query above produces a string, such as '2011-1', that identifies the year and quarter. Of course, you don't have to include the year if you don't want to.
If you want the DATEs when the previous quarter began and ended:
SELECT     ADD_MONTHS ( TRUNC (SYSDATE, 'Q')
             , -3
             )               AS begin_date
,     TRUNC (SYSDATE, 'Q') -1          AS end_date
FROM     dual
;TRUNC (dt, 'Q') returns the first DATE in the same quarter as dt.

Similar Messages

  • Generating SQL in a PL/SQL progam ( getting the values of a value)

    Hi,
    We're using Oracle 11.1.
    I want to generate sql to do the following
    something like
    fld_pos(i) = 'MPI';Where fld_pos is part of a varray.
    The basic procedire is below.
    PROCEDURE get_oldest_mpi (
          pin_fld0 VARCHAR2
        , pin_fld1 VARCHAR2
        , pin_fld2 VARCHAR2
        , pin_fld3 VARCHAR2
        , pin_fld4 VARCHAR2
        , pin_fld5 VARCHAR2
        , pin_fld6 VARCHAR2
        , pin_fld7 VARCHAR2
        , pin_fld8 VARCHAR2
        , pin_fld9 VARCHAR2
        , pin_fld10 VARCHAR2
        , pin_fld11 VARCHAR2
        , pin_fld12 VARCHAR2
        , pin_fld13 VARCHAR2
    IS
         TYPE fld IS VARRAY(14) OF VARCHAR2(50);
         fld_pos fld;
         v_sql_stmt VARCHAR2(1000);
         mpi_pos  number;
    BEGIN
    --load the pin_fld vars into an array so they can be processed in a loop
        FOR i IN 1..fld_pos.COUNT
        LOOP
        fld_pos(i) := 'pin_fld'||i;
        END LOOP;
    --see if the variable pin_fld'x' = the word 'MPI'
        FOR i IN 1..fld_pos.COUNT
        LOOP
        IF  fld_pos(i) = 'MPI' then    -- I know this statement is wrong. This is where I need help.
          mpi_pos :=i;
        END IF;
        END LOOP;
    .I know that 'fld_pos(i)' equals 'pin_fld||i .
    So how do I get to the value in the value for this? How can generate the SQL to get the expression I need?
    Thanks,

    Hi,
    It's still an awkward procedure, but
    CREATE OR REPLACE PROCEDURE get_oldest_mpi (
      pin_fld0     VARCHAR2,
      pin_fld1     VARCHAR2,
      pin_fld2     VARCHAR2,
      pin_fld3     VARCHAR2,
      pin_fld4     VARCHAR2,
      pin_fld5     VARCHAR2,
      pin_fld6     VARCHAR2,
      pin_fld7     VARCHAR2,
      pin_fld8     VARCHAR2,
      pin_fld9     VARCHAR2,
      pin_fld10    VARCHAR2,
      pin_fld11    VARCHAR2,
      pin_fld12    VARCHAR2,
      pin_fld13    VARCHAR2
    ) IS
      TYPE fld IS VARRAY (14) OF VARCHAR2 (50);
      fld_pos      fld
                     := fld (pin_fld0,
                             pin_fld1,
                             pin_fld2,
                             pin_fld3,
                             pin_fld4,
                             pin_fld5,
                             pin_fld6,
                             pin_fld7,
                             pin_fld8,
                             pin_fld9,
                             pin_fld10,
                             pin_fld11,
                             pin_fld12,
                             pin_fld13
      v_sql_stmt   VARCHAR2 (1000);
      mpi_pos      NUMBER;
    BEGIN
      --see if the variable pin_fld'x' = the word 'MPI'
      FOR i IN 1 .. fld_pos.COUNT LOOP
        IF fld_pos (i) = 'MPI' THEN
          mpi_pos := i;
        END IF;
      END LOOP;
    END;
    /Regards
    Peter

  • Prep 2007 Upgrade - SQL to Get Clients Started

    <u><b>Prep for SAP 2007 - Some SQL to Get the Clients Started</b></u>
    (NOTE: Marilyn Pratt suggested I post this here since it is so general.  If there is a better place, please let me know and I can move/post it there).
    I have just started working with a customer doing international business; pre-payments and block payments are 90% of their business.  They have not reconciled items for almost three years in SAP B1.  In my discussions with them about SAP 2007, they wanted to be a bit more proactive in dealing with reconciliations before SAP 2007 arrived.  In order to get them moving quickly, I wrote the following versions of SQL which identifies business partners with a zero account balance and open documents/journal entries (what easier way is there to start?).  If you find yourself in a similar situation, you might want to utilize this SQL to gently guide your customers into looking at unreconciled/unmatched situations. The SQL is simple, but direct.  It might be written a lot better, but the whole purpose was to get the customer to START doing something.  Two side benefits; one, the results of the SQL provide 100% success in what they are doing and they gain some confidence in a new process, and two, the customer can run this on a daily basis to keep things “clean”.  Once they are done with this easy-to-do phase, I will put something together that might help with those items needing more research. 
    Might have made a mistake while re-typing the SQL for this post, so check them out and leave a note if I typed something wrong, OK?  It’s not much, but hope these help those who might be in a similar situation!
    (note – the two dashed items are just info only and not do not need to be put in the actual SQL you write).
    <u><b>--SQL to Identify Business Partners with Zero Balance and Open Documents</b></u>
    SELECT
    --T10 = Business Partner Master Data Information
    T10.CardCode AS ‘BP Code’,
    T10.Cardname AS ‘BP Name’,
    T10.Balance AS ‘BP Account Balance’,
    --T20 = Invoice Header Information
    Sum(T20.DocTotal) AS ‘Total Open Invoices’,
    Sum(T20.PaidToDate) AS ‘Total Paid To Date’,
    --T30 = Credit Memo Header Information
    Sum(T30.DocTotal) AS ‘Total Cred Memo Info’
    FROM OCRD T10 INNER JOIN OINV T20
    ON T10.CardCode = T20.Card Code
    AND T20.DocStatus = 'O'
    --NOTE:  use OINV for customer BPs, substitute ORPC for OINV to get a report on BPs that are vendors
    LEFT OUTER JOIN ORIN T30
    ON T10.CardCode = T30.CardCode
    AND T30.DocStatus = 'O'
    WHERE T10.Balance = 0
    GROUP BY T10.CardCode, T10.CardName, T10.Balance
    ORDER BY T10.CardCode, T10.CardName
    --END OF SQL to Identify Business Partners with Zero Balance and Open Documents
    Another version that could help.
    <u><b>--SQL to Identify Business Partners with Zero Balance and Unmatched Journal Entries</b></u>
    --T10 = Journal Entry Header Information
    T10.TransID,
    --T20 = Journal Entry Detail Information
    T20.IntrnMatch AS ‘Intern Match ID’,
    T20.ShortName AS ‘JE BP Code’,
    Sum(T20.Debit) AS ‘JE Debit Total’,
    Sum(T20.Credit) AS ‘JE Credit Total’,
    --T30 = Business Partner Master Data Information
    T30.CardCode AS ‘BP Num’,
    T30.Balance AS ‘BP Account Balance’
    FROM OJDT T10 INNER JOIN JDT1 T20
    ON T10.TransID = T20.TransID
    LEFT OUTER JOIN OCRD T30
    ON T20.ShortName = T30.CardCode
    AND T30.Balance = 0
    WHERE T20.IntrnMatch = ‘ ‘
    --NOTE:  that is a single quote mark, space, and another single quote mark for IntrnMatch
    GROUP BY T20.ShortName, T20.IntrnMatch, T30.CardCode, T30.Balance
    ORDER BY T20.ShortName
    --END OF SQL to Identify Business Partners with Zero Balance and Unmatched JEs.

    Hi,
    What is the native vlan you are using ? If it is vlan number 2, then there is known bug CSCui73764
    Symptom:
    Flex mode APs 1130 & 1240 series, will not pass traffic, e.g. DHCP, ARP. on some wlans.
    Conditions:
    1) Flex connect local switching
    2) AP 1240 or 1130
    3) any version before 7.4.121.7
    4) native vlan x, non working vlan y.
    5) user unable to get ip address.
    Workaround:
    change the native vlan to an unexpectedly high number, so no wlan will ever get mapped to a bridge group number that high.
    Further Problem Description:
    telnet to the flex ap. here is an example. vlan 3 is the native vlan on the flex ap, it is correctly mapped to bridge group 1. now the wlan which will not work is the one, which is mapped to vlan2. see carefully below, the vlan 2 is mapped to bridge group 3. this is the instance where we hit the bug. so it can be any wlan-vlan-native vlan combination. 
    HTH
    Rasika
    **** Pls rate all useful responses ****

  • Pl sql packages getting invalid

    Hi All,
    I am working on a OLTP VLDB oracle 10g database. I have observed that many of pl sql packages get in invalid state. There are many cronjobs , dbms jobs running 24x7. How do I find out the root cause of this?

    You can write Database DDL trigger and log DDL operation into your log table.
    Then check which statement caused it:
    CREATE OR REPLACE TRIGGER DDL_TRIG BEFORE
    ON DATABASE
      INSERT INTO YOUR_LOG_TABLE
      SELECT ora_sysevent, ora_dict_obj_owner,
      ora_dict_obj_name, NULL, USER, SYSDATE
      FROM dual You should check if table which caused trigger to fire is dependency of your desired package like
    where ora_dict_obj_name in (
      select referenced_name from dba_dependencies where name IN(YOUR_INVALIDATED_PACK_LIST) and   
       referenced_type='TABLE';
      )

  • Teststand SQL reuest get MAX of a Column

    Spoiler (Highlight to read)
    Hello,
    In Teststand 3.1, I try to get the MAX of a column called  Col1 in the table myTAB.
    To do that; I have writen in the Open Statement the following request
    SELECT MAX(myTAB.Col1) FROM myTAB" Thanks. Correct execution in teststand
    Question : How do I get the result with the SQL Action Step
    Thank you by advance for your help
    Solved!
    Go to Solution.

    Hello Rodéric,
    Thank you very much for the answer.
    I tried your suggestion as it is but unfortunatelly Teststand gives back an error because it can't manage correctly the locals.max in the request.
    However I tried other may your idea of using the key word "as" :
    First I use :
    Open Statement : SELECT MAX(myTAB.Col1) as MAXI FROM myTAB
    I don't know how teststand manage the "variable" MAXI.
    But when I secondly add the step
    SQL Action : Get - Retrive Values from record with as Column/Parameter Values:
    Name/Number : "MAXI"
    Values : Locals.Max
    It works correctly
    Thank you a lot
    Ham

  • Get a quarter out of data for a column chart

    Who can help me with this challenge?
    I want to create a column chart with four quarters in the current year and one column with the rest later in time.
    One project can have multiple output data. They are separated by an ;
    The notation of the outputdata can be a date (d-m-yyyy), a month (mm-yyyy) or a quarter (Q1-yyyy).
    This is by example the available data.
    Project              outputdata
    Project 1           1-4-2014
    Project 2           03-2014;Q4-2014;Q2-2015
    Project 3           25-09-2014;Q1-2015
    The data I want to get for the column chart is:
    Project              outputdata                    columnchart
    Project 1           1-4-2014                       Q2-2014
    Project 2           03-2014                        Q1-2014
    Project 2           Q4-2014                       Q4-2014
    Project 2           Q2-2015                       2015 and later
    Project 3           25-09-2014                   Q3-2014
    Project 3           Q1-2015                       2015 and later
    I hope that someone can help me in the right direction.
    Thanks in advance,
    Els

    Adding to what Frank has already suggested, try something on these lines:
    Something like this?
    SQL> ed
    Wrote file afiedt.buf
      1  with x2 as(
      2     select 'proj1' proj, '1-4-2014' op, NULL chart from dual UNION ALL
      3     select 'proj2' proj, '03-2014' op, NULL chart from dual UNION ALL
      4     select 'proj2' proj, 'Q4-2014' op, NULL chart from dual UNION ALL
      5     select 'proj2' proj, 'Q2-2015' op, NULL chart from dual UNION ALL
      6     select 'proj3' proj, '25-09-2014' op, NULL chart from dual UNION ALL
      7     select 'proj3' proj, 'Q1-2015' op, NULL chart from dual
      8  )
      9  select
    10     proj,
    11     op,
    12     case
    13     when regexp_like(op,'((\d{1}|\d{2})-(\d{1}|\d{2})-(\d{4}))')
    14     then
    15             'Q'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'yyyy')
    16     when regexp_like(op, 'Q\d{1}-\d{4}')
    17     then
    18             CASE
    19             when SUBSTR(op,-4,4) > 2014
    20             then
    21                     SUBSTR(op,-4,4)||' and later'
    22             else
    23                     op
    24             end
    25     when regexp_like(op, '\d{2}-\d{4}')
    26     then
    27             'Q'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'yyyy')
    28     end
    29* from x2
    SQL> /
    PROJ       OP                   CASEWHENREGEXP
    proj1      1-4-2014             Q2-2014
    proj2      03-2014              Q1-2014
    proj2      Q4-2014              Q4-2014
    proj2      Q2-2015              2015 and later
    proj3      25-09-2014           Q3-2014
    proj3      Q1-2015              2015 and later
    6 rows selected.

  • Unable to generate the XML file through SQL script. getting error PLS-00306

    I am fetching the data from cursor and generating the xml output I am getting the below error.
    When I have checked the cursor query it is fetching the data in to single column.
    Input truncated to 1 characters
    Enter value for 7: EXEC FND_CONC_STAT.COLLECT;
    DBMS_LOB.append (tmp_file, r.core_xml);
    ERROR at line 95:
    ORA-06550: line 95, column 7:
    PLS-00306: wrong number or types of arguments in call to 'APPEND'
    ORA-06550: line 95, column 7:
    PL/SQL: Statement ignored

    Hi Alex,
    thanks for the responce..
    i have fixed the issue
    i have used XMLAttributes to get the value
    SELECT XMLELEMENT (
    NAME "TranACK",
    XMLAttributes ('1' as "TranNum",
    (select distinct to_char(SYSDATE,'yyyy-mm-dd')
    from DUAL) as "PrcDate"),
    XMLFOREST (
    a.PAYMENT_ID AS "PmtID"),
    XMLFOREST (
    a.ACK_TRANSACTION_RECEIVER AS "Name1"),
    XMLFOREST (
    to_char(a.VALUE_DATE,'yyyy-mm-dd') as "ValueDate" ),
    XMLFOREST (
    a.PAYMENT_AMOUNT AS "CurAmt"),
    XMLFOREST (
    a.CURRENCY_CODE AS "CurCode")
    ).getclobval ()
    AS line_xml
    FROM XXWAP_PAYMENT_LINE_TBL a
    where a.PAYMENT_BATCH_ID=P_batch_id;

  • How to get Current Quarter and Fiscal Quarter for a Date - Fiscal Year starts from 1st April

    Hi, 
    I need to calculate current quarter and fiscal quarter in my Sql query.
    I have a column for DateTime Datatype. 
    I need to find out Current Quarter Name like Q12012, Q22012, Q32012, Q42012 and Fiscal Quarter Name as well.
    Now Fiacal Year starts from 1st April, and Current Quarter starts from 1st Jan.
    For Current Quarter of 2012
    Jan-Mar = Q12012
    Apr-Jun = Q22012
    Jul-Sep = Q32012
    Oct-Dec = Q42012
    For Fiscal Quarter of 2012 ( starts from 1st Apr, 2011 )
    Apr2011-Jun2011 = Q12012
    Jul2011-Sep2011 = Q22012
    Oct2011-Dec2011 = Q32012
    Jan2011-Mar2012 = Q42012
    means if its 1st April, 2012,
    its a new Fiacal Year 2013 so Fiacal Quarter Name should be Q12013
    and its Current Quarter Name should be Q22012
    Can you help me to calculate this in a select query for given dates?
    Thanks in advance, 
    Nirav

    This should do it..
    Select
    FORMAT(datepart(quarter,getdate()),'Q#')+FORMAT(getdate(),'yyyy')

  • Query SQL code gets deleted after export to Excel. "Query must have at least one destination field"

    Hi all,
    I'm getting really frustrated by this Access error. It happens when I export the result of a query through an Access macro to Excel, the first time it runs well but the next time, there is a chance that the query won't run and the error "Query
    must have at least one destination field" will be displayed. After that, I try to check the query SQL code and discover the code has vanished. I'm using simple Select query without joins, only "where", "group by" and "order by"
    statements.
    Thank you in advance for your help,
    Jesus 
    Edit:
    One of these queries are like the following (all of them are of this type):
    SELECT Field1, field2, field3, field4, field5, Sum(Field6) AS SumOfField6, Sum(Field7) AS SumOfField7
    FROM Table1
    WHERE Field6 is not null
    GROUP BY Field1, field2, field3, field4, field5
    Order By Sum(Field6) desc

    Hi Peter, 
    Thank you for your response, I updated the original question with one of the codes.
    Thanks,
    Jesus

  • SQL Worksheet Gets Slower and S.l..o...w....e.....r with Use

    Does anyone else notice the more you use SQL Worksheet, the
    slower it gets? The first time I start it up, it'll run a
    compile on an object super-fast. After running a dozen or more
    compiles and test scripts, I notice it's getting slower.
    Eventually, it's so slow I just kill SQL Worksheet and start it
    right back up. Then it's back to warp speed again!
    I'm on a Win2K machine, running Oracle 8.0.6, with version 1.6.0
    of SQL Worksheet.
    I have 2.1 install disc for Oracle Enterprise Manager, but I'm
    uncertain if I can update what I've got (given the release of
    Oracle I'm on). Any help here would be appreciated, too.

    The box does not reboot itself at 7am every day at the behest of BT that is not normal behaviour.
    I think you really ought to fo  a hard reset and clear everything off your hard drive and see if it solves your problem.
    If it does not then you are I think looking at a slowly dying box which needs to be replaced.
    Factory Reset
    Switch off the Vision+ box at the mains socket
    Hold down the front panel OK and down arrow buttons
    Switch on the power to the Vision+ box
    Allow the box to start up (about 15 seconds)
    Release the OK and down arrow buttons
    The Vision+ box will then contact the servers to get a new copy of its firmware
    This will take around 30 minutes
    Life | 1967 Plus Radio | 1000 Classical Hits | Kafka's World
    Someone Solved Your Question?
    Please let other members know by clicking on ’Mark as Accepted Solution’
    Helpful Post?
    If a post has been helpful, say thanks by clicking the ratings star.

  • SQL to get System Time/Date from Access 95

    Is it possible to query Access 95 in SQL to return the system (current) time and date?
    Kinda like a sysDate call would do in Oracle...?

    Won't that only return the date of the most current
    record? I'm talking about the actual system
    date..(The main clock where the dates that get created
    are based on)It returns the system date and time. Just try to see.

  • PL/SQL Region : Getting values from PL/SQL generated form?  (APEX 2.2.0)

    Hi, all,
    If I've got an PL/SQL region that dynamically generates a form using HTMLDB_ITEM.TEXTAREA, what is the best way to get the contents of those form data at submit time?
    Thanks,
    Don
    Message was edited by:
    Don_84
    Edited for clarity.

    Don,
    The apex_item (nee htmldb_item) functions take an index number as a parameter. So if you give the textarea function p_idx=>1, it creates item f01. If you give it p_idx=>2, it creates item f02, etc. In your after-submit code, access the package variable apex_application.g_fxx where xx is the index number you used.
    Scott

  • SQL not getting executed

    Hi,
    My sql below is not getting executed.There are no errors but even after long time it is not producing any thing (error or result).
    I am getting results till the statement SELECT D.budeptmap_v88_dept_id ,
    but when I right the last statement on top of this nothing is coming.
    select u.dw_code_skey,u.dw_code from dw.agg_inscope_top_nodes t, dw.dw_codes u
    where
    t.TOP_NODE_TR_HDR_SKEY = u.DW_CODE_TR_HDR_SKEY
    and u.DW_CODE_SUPERTYPE_CODE = 'DEPT'
    and u.DW_CODE_DW_CUR_IND = 'Y'
    and u.DW_CODE_DW_DEL_IND = 'N'
    and u.DW_CODE in(
    SELECT D.budeptmap_v88_dept_id
    from DW.CLIENT_ACCOUNTS C,DW.AON_V75_V88_BU_DEPT_MAP_SDO D
    WHERE D.budeptmap_v75_dept_id = '-1'
    AND D.budeptmap_v75_bu_id IN(C.cli_acct_producing_offICE_code)
    AND C.CLI_ACCT_DW_CUR_IND='Y'
    AND CLI_ACCT_SKEY IN (
    SELECT A.CLI_SUM_CLI_ACCT_SKEY
    FROM PROFIT.FACT_CLIENT_SUMMARIES A
    WHERE A.CLI_SUM_PERIOD_SKEY = 3
    AND A.DM1_TOT_ADJUSTED_REV_AMT =
    (SELECT MAX(DM1_TOT_ADJUSTED_REV_AMT)
    FROM PROFIT.FACT_CLIENT_SUMMARIES B
    WHERE B.CLI_SUM_ENTITY_SKEY =A.CLI_SUM_ENTITY_SKEY
    AND B.CLI_SUM_PERIOD_SKEY =3)))
    any help in tunning is highly appreciated.
    Thanks in advance

    how long does this query takes to complete?
            SELECT D.budeptmap_v88_dept_id
              from DW.CLIENT_ACCOUNTS C,
                   DW.AON_V75_V88_BU_DEPT_MAP_SDO D
             WHERE D.budeptmap_v75_dept_id = '-1'
               AND D.budeptmap_v75_bu_id IN (C.cli_acct_producing_offICE_code)
               AND C.CLI_ACCT_DW_CUR_IND = 'Y'
               AND CLI_ACCT_SKEY IN (SELECT A.CLI_SUM_CLI_ACCT_SKEY
                                       FROM PROFIT.FACT_CLIENT_SUMMARIES A
                                      WHERE A.CLI_SUM_PERIOD_SKEY = 3
                                        AND A.DM1_TOT_ADJUSTED_REV_AMT =
                                            (SELECT MAX(DM1_TOT_ADJUSTED_REV_AMT)
                                               FROM PROFIT.FACT_CLIENT_SUMMARIES B
                                              WHERE B.CLI_SUM_ENTITY_SKEY =A.CLI_SUM_ENTITY_SKEY
                                                AND B.CLI_SUM_PERIOD_SKEY =3))

  • Portal PL/SQL Item - getting connection id for Discoverer

    Finding the connection ID of a connection in Portal PL/SQL item.
    I am using a PL/SQL item in Portal to build a link to Oracle Discoverer.
    Everything is ok; except the user needs to enter a password to login to discoverer.
    I want to start discoverer plus using a private connection. The private connection ID of each user will be different.
    Is there any PL/SQLcode I can use to get this information?
    I am using to PORTAL.wwctx_api.get_user to get userid. I would like to dynamically get the connection id.
    I have hardcoded a private connection id and the link worked fine.
    Since each user has a unique private connection the hardcoding is not practical.
    Any help would be appreciated!! Thanks.

    Hi,
    I'm looking for the same answer. Anything?
    regards
    Malin

  • Help with oracle sql to get all possible combinations in a table.

    Hello guys I have a small predicatement that has me a bit stumped. I have a table like the following.(This is a sample of my real table. I use this to explain since the original table has sensitive data.)
    CREATE TABLE TEST01(
    TUID VARCHAR2(50),
    FUND VARCHAR2(50),
    ORG  VARCHAR2(50));
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
    Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
    Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "955542224"                   "1500XX"                      "67150"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                       The "X"'s are wild card elements*( I inherit this and i cannot change the table format)* i would like to make a query like the following
    select tuid from test01 where fund= '100000' and org= '67130'however what i really like to do is retrieve any records that have have those segements in them including 'X's
    in other words the expected output here would be
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"  i have started to write a massive sql statement that would have like 12 like statement in it since i would have to compare the org and fund every possible way.
    This is where im headed. but im wondering if there is a better way.
    select * from test02
    where fund = '100000' and org = '67130'
    or fund like '1%' and org like '6%'
    or fund like '1%' and org like '67%'
    or fund like '1%' and org like '671%'
    or fund like '1%' and org like '6713%'
    or fund like '1%' and org like '67130'
    or fund like '10%' and org like '6%'...etc
    /*seems like there should be a better way..*/can anyone give me a hand coming up with this sql statement...

    mlov83 wrote:
    if i run this
    select tuid,fund, org
    from   test01
    where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');this is what i get
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                      
    "9148859fff"                  "1XXXXXX"                     "X6XXX"                       the last item should be excluded. The second digit in "org" is a "7" Fund is wrong, too. You're looking for 6 characters ('100000'), but fund on that row is 7 characters ('1XXXXXX').
    and this is sitll getting picked up.That's why you should use the _ wild-card, instead of %
    select  tuid, fund, org
    from    test01
    where  '100000' like translate (fund, 'xX', '__')
    and    '67130'  like translate (org,  'xX', '__')
    ;It's hard to see, but, in both calls to TRANSLATE, the 3rd argument is a string of 2 '_'s.

Maybe you are looking for