UCCX SQL query assistance needed.

Hello,
I am working on a SQL query that does a lookup of the calling number and the last four digits entered by the customer.  If I hard code the lastFourGC variable I am able to return a successful result.  If I use $lastFourGC I get the following error.
$callingNumber  - Is exactly that, the calling number.
$lastFourGC - Is the last four digits collected from the customer.
SELECT * FROM GiftCardFulfillment WHERE Phone=$callingNumber and Right (GiftCard16DigitNumber, 4)=$lastFourGC

Tanner,
I had tried that with single and double quotes and it didn't work.  I did end up getting it to work by rearranging the order.  I'm not sure why that worked, but this is what the query looks like now and it works.
SELECT * FROM [leads].[dbo].[GiftCardFulfillment]   
         WHERE Right (GiftCard16DigitNumber, 4)=$lastFourGC and Phone=$callingNumber

Similar Messages

  • What SQL query I need for this?

    I need to execute a SQL query but I don't know how.
    To illustrate it, please take a look at some example data:
        ARTICLEID SOLDON    
        1         2005-12-31
        1         2005-11-31
        1         2005-10-31
        1         2005-09-31
        1         2005-08-31
        1         2005-07-31
        1         2005-06-31
        1         2005-05-31
        1         2005-04-31
        1         2005-03-31
        1         2005-02-31
        1         2005-01-31
        1         2004-12-31
        1         2004-11-31
        2         2005-12-31
        2         2005-11-31
        2         2005-10-31
        2         2005-09-31 This is a piece of the sales data for the articles (sales history).
    Lets assume that today is the date 2005-12-31.
    Two requirements for the query:
    1. Get the sales data for the last 12 months.
    2. Get only the sales data for articles where there is sales data since at least 6 months.
    The result in my example should look like this:
        ARTICLEID SOLDON    
        1         2005-12-31
        1         2005-11-31
        1         2005-10-31
        1         2005-09-31
        1         2005-08-31
        1         2005-07-31
        1         2005-06-31
        1         2005-05-31
        1         2005-04-31
        1         2005-03-31
        1         2005-02-31
        1         2005-01-31 What is the SQL which I need to accomplish this query?

    To get all the information from the last 12 months
    you will have to use date manipulation.
    SELECT add_months(sysdate, -12) from
    dual;This gives you the date 12 months ago.
    So you will have to select your date between then and
    the current date.If I do this I will get this data:
        ARTICLEID SOLDON    
        1         2005-12-31
        1         2005-11-31
        1         2005-10-31
        1         2005-09-31
        1         2005-08-31
        1         2005-07-31
        1         2005-06-31
        1         2005-05-31
        1         2005-04-31
        1         2005-03-31
        1         2005-02-31
        1         2005-01-31
        2         2005-12-31
        2         2005-11-31
        2         2005-10-31
        2         2005-09-31 But I want this data:
        ARTICLEID SOLDON    
        1         2005-12-31
        1         2005-11-31
        1         2005-10-31
        1         2005-09-31
        1         2005-08-31
        1         2005-07-31
        1         2005-06-31
        1         2005-05-31
        1         2005-04-31
        1         2005-03-31
        1         2005-02-31
        1         2005-01-31 I am no native English speaker. What didn't you understand in the two requirements?
    Here are my two requirements for the query:
    1. Get the sales data for the last 12 months.
    2. But get ONLY the sales data for articles where there is sales data since AT LEAST 6 months.
    The result can contain as many IDs as you want if the two requirements are met. Its not a trivial SQL statement for me. Please remember that the above data are only for illustration. They are just an example.
    There should be a SQL statement for this.
    Please tell me if you don't understand my problem. I will try to explain it in a better way if I can.

  • SQL Query Assistance Required for Full Outer Join

    Hi,
    Lets say I have two tables, i.e:
    TAB_A (colA1, colA2, colA3, colA4)
    TAB_B (colB1, colB2, colB3, colB4) where colB2 is a FK to colA1
    I am after an SQL query that will cater for both the following two scenarios.
    Scenario 1:
    TAB_A has two rows of data, i.e
    (1, ABC100, 1, WG_A)
    (2, ABC100, 2, WG_B)
    TAB_B has one row of data, i.e
    (1, 1, EMP_222, 4)
    I use the following SQL:
    select a.*, b.*
    from tab_a a FULL OUTER JOIN tab_b b ON (a.colA1 = b.colB2)
    where a.colA2 = 'ABC100'
    This returns two rows:
    1, ABC100, 1, WG_A, 1, 1, EMP_222, 4
    2, ABC100, 2, WG_B
    Now, what I actually would like my query to do is actually only return the row where a tab_b record exists, i.e, should only return one record:
    1, ABC100, 1, WG_A, 1, 1, EMP_222, 4
    This I can achieve by using a RIGHT OUTER JOIN instead above, but this causes issue with my scenario 2, which is the following set-up
    Scenario 2:
    TAB_A has only one row of data this time, i.e
    (2, ABC100, 2, WG_B)
    TAB_B has no data at all this time
    This returns no rows but I actually now want this single record from tab_a returned.
    I basically require an SQL query that will cater for both the top 2 scenarios, i.e, if a tab_b record exists from the outer join then only return this record along with tab_a data. If a tab_b record doesn't exist, then only return the tab_a record.
    Hope the above makes sense.
    Thanks.

    Is it what you need (not very elegant) ?
    SQL> select * from t_outer;
            ID CODE
             1 100
             2 100
    SQL> select * from t_inner;
    no rows selected
    SQL> with tab1 as (
      2  select a.id a_id, a.code, b.id b_id from t_outer a join t_inner b on
      3  (a.id = b.id and a.code = '100'))
      4  select * from tab1
      5  union all
      6  select a.*, null from t_outer a where not exists (
      7  select 1 from tab1)
      8  and a.code = '100'
      9  /
          A_ID CODE             B_ID
             1 100
             2 100
    SQL> insert into t_inner values(2);
    1 row created.
    SQL> with tab1 as (
      2  select a.id a_id, a.code, b.id b_id from t_outer a join t_inner b on
      3  (a.id = b.id and a.code = '100'))
      4  select * from tab1
      5  union all
      6  select a.*, null from t_outer a where not exists (
      7  select 1 from tab1)
      8  and a.code = '100'
      9  /
          A_ID CODE             B_ID
             2 100                 2
    Rgds.

  • SQL Query Help Needed

    I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
    private void LogOn() {
    //make sure that the user name/password is valid, then load the main menu
    try {
    //open the database connection
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
    Statement select = con.createStatement();
    String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
    ResultSet result = select.executeQuery(strTemp);
    while(result.next()) {
    if (txtPassword.getPassword().toString() == result.getString("Password")) {
    MenuMain.main();
    else {
    System.out.println("Password Bad");
    System.out.println(txtUserName.getText());
    System.out.println(result.getString("Password"));
    break; //exit loop
    //close the connection
    con.close(); }
    catch (Exception e) {
    System.out.println("LawOfficeSuite_LogOn: " + e);
    return; }
    }

    The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
    Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
    Example:String s1 = "foo";
    String s2 = new String("foo");
    System.out.println("s1 == s2: " + (s1 == s2)); // false
    System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus ==

  • SQL Query Performance needed.

    Hi All,
       I am getting performance issue with my below sql query. When I fired it, It is taking 823.438 seconds, but when I ran query in, it is taking 8.578 seconds, and query after in   is taking 7.579 seconds.
    SELECT BAL.L_ID, BAL.L_TYPE, BAL.L_NAME, BAL.NATURAL_ACCOUNT,
     BAL.LOCATION, BAL.PRODUCT, BAL.INTERCOMPANY, BAL.FUTURE1, BAL.FUTURE2, BAL.CURRENCY, BAL.AMOUNT_PTD, BAL.AMOUNT_YTD, BAL.CREATION_DATE,
     BAL.CREATED_BY, BAL.LAST_UPDATE_DATE, BAL.LAST_UPDATED_BY, BAL.STATUS, BAL.ANET_STATUS, BAL.COG_STATUS, BAL.comb_id, BAL.MESSAGE,
     SEG.SEGMENT_DESCRIPTION  FROM ACC_SEGMENTS_V_TST SEG , ACC_BALANCE_STG BAL where BAL.NATURAL_ACCOUNT = SEG.SEGMENT_VALUE AND SEG.SEGMENT_COLUMN = 'SEGMENT99' AND BAL.ACCOUNTING_PERIOD = 'MAY-10' and BAL.comb_id
    in  
    (select comb_id from
     (select comb_id, rownum r from
      (select distinct(comb_id),LAST_UPDATE_DATE from ACC_BALANCE_STG where accounting_period='MAY-10' order by LAST_UPDATE_DATE )    
         where rownum <=100)  where r >0)
    Please help me in fine tuning above. I am using Oracle 10g database. There are total of 8000 records. Let me know if any other info required.
    Thanks in advance.

    In recent versions of Oracle an EXISTS predicate should produce the same execution plan as the corresponding IN clause.
    Follow the advice in the tuning threads as suggested by SomeoneElse.
    It looks to me like you could avoid the double pass on ACC_BALANCE_STG by using an analytical function like ROW_NUMBER() and then joining to ACC_SEGMENTS_V_TST SEG, maybe using subquery refactoring to make it look nicer.
    e.g. something like (untested)
    WITH subq_bal as
        ((SELECT *
          FROM (SELECT BAL.L_ID, BAL.L_TYPE, BAL.L_NAME, BAL.NATURAL_ACCOUNT,
                 BAL.LOCATION, BAL.PRODUCT, BAL.INTERCOMPANY, BAL.FUTURE1, BAL.FUTURE2,
                 BAL.CURRENCY, BAL.AMOUNT_PTD, BAL.AMOUNT_YTD, BAL.CREATION_DATE,
                 BAL.CREATED_BY, BAL.LAST_UPDATE_DATE, BAL.LAST_UPDATED_BY, BAL.STATUS, BAL.ANET_STATUS,
                 BAL.COG_STATUS, BAL.comb_id, BAL.MESSAGE,
                 ROW_NUMBER() OVER (ORDER BY LAST_UPDATE_DATE) rn
                 FROM   acc_balance_stg
                 WHERE  accounting_period='MAY-10')
          WHERE rn <= 100)
    SELECT *
    FROM   subq_bal bal
    ,      acc_Segments_v_tst seg
    where  BAL.NATURAL_ACCOUNT = SEG.SEGMENT_VALUE
    AND    SEG.SEGMENT_COLUMN = 'SEGMENT99';However, the parentheses you use around comb_id make me question what your intention is here in the subquery?
    Do you have multiple rows in ACC_BALANCE_STG for the same comb_id and last_update_date?
    If so you may want to do a MAX on last_update_date, group by comb_id before doing the analytic restriction.
    Edited by: DomBrooks on Jun 16, 2010 5:56 PM

  • Sql query ..need idea to write complex query

    Hi there,
    I have assigned the task to write a sql query to get the output as the below stored proc does.
    In the proc conditions are given with IF statements. I really dont know how to give all the conditions for the period in a single sql query as I'm not much used to sql quries.
    Is anyone could help me?
    Any suggestions pls . writing complicated query is nightmare. no idea . if possible help me...
    create or replace PROCEDURE vpp_station_summary_report (
    in_user_id                     IN  VARCHAR2,
    in_report_id      IN  NUMBER,
    in_time_from                IN      vppstation.avi_status_history.status_eff_date%TYPE,
    in_time_to                  IN  vppstation.avi_status_history.status_eff_date%TYPE,
    result                               OUT SYS_REFCURSOR)
    AS
    CURSOR station_loop IS
       SELECT ash.station_id,
              ash.avi_id,
              ash.state_id,
              ash.state_eff_date
       FROM   vppstation.avi_state_history ash
       JOIN   vpproadside.vpp_report_stations
         ON   vpp_report_stations.station_id             = ash.station_id
        AND   vpp_report_stations.vpp_report_seq_number  = in_report_id
       WHERE  ash.state_eff_date BETWEEN in_time_from AND in_time_to
       ORDER BY ash.station_id,
                ash.avi_id,
                ash.state_eff_date,
                ash.ash_id;
    -- cursor to find the 'entry state' i.e. the state the AVI was in AT the time of
    -- in_time_from
    CURSOR entry_state (
              state_station_id vppstation.avi_state_history.station_id%TYPE,
              state_avi_id     vppstation.avi_state_history.avi_id%TYPE,
              state_state_date vppstation.avi_state_history.state_eff_date%TYPE
    IS
       SELECT ash.state_id
       FROM   vppstation.avi_state_history ash
       WHERE  ash.station_id = state_station_id
         AND  ash.avi_id = state_avi_id
         AND  ash.state_eff_date < state_state_date
       ORDER BY ash.state_eff_date DESC,
                ash.ash_id DESC;
    current_station_id         vppstation.avi_state_history.station_id%TYPE;
    current_avi_id             vppstation.avi_state_history.avi_id%TYPE;
    current_state_id           vppstation.avi_state_history.state_id%TYPE;
    current_state_eff_date     vppstation.avi_state_history.state_eff_date%TYPE;
    period_length NUMBER;
    next_station_id     vppstation.avi_state_history.station_id%TYPE;
    next_avi_id         vppstation.avi_state_history.avi_id%TYPE;
    next_state_id       vppstation.avi_state_history.state_id%TYPE;
    next_state_eff_date vppstation.avi_state_history.state_eff_date%TYPE;
    station_open_total       NUMBER;
    station_closed_total     NUMBER;
    station_all_report_total NUMBER;
    current_station_name vpproadside.vpp_station_summary.station_name%TYPE;
    state_open       vppstation.avi_control_state_code.state_id%TYPE;
    state_closed     vppstation.avi_control_state_code.state_id%TYPE;
    state_all_report vppstation.avi_control_state_code.state_id%TYPE;
    BEGIN
    SELECT state_id
    INTO   state_open
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'E'
    AND    state_active_ind = 'A';
    SELECT state_id
    INTO   state_closed
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'D'
    AND    state_active_ind = 'A';
    SELECT state_id
    INTO   state_all_report
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'S'
    AND    state_active_ind = 'A';
    current_station_id := -1;
    current_avi_id     := -1;
    current_state_id   := state_closed;
    current_state_eff_date := in_time_from;
    station_open_total       := 0.0;
    station_closed_total     := 0.0;
    station_all_report_total := 0.0;
    -- for starters - ensure that there is report data for all requested stations...
    INSERT INTO vpproadside.vpp_station_summary
          vpp_report_seq_number,
          station_id,
          station_name,
          ln_number,
          lane_name,
          station_open,
          station_close,
          station_all_report,
          station_total
      SELECT in_report_id,
             vrs.station_id,
             si.station_name,
             l.ln_number,
             l.lane_name,
             0.0,
             0.0,
             0.0,
             0.0
      FROM vpproadside.vpp_report_stations vrs
      LEFT OUTER JOIN  vpproadside.stations_installed si
        ON  si.station_id = vrs.station_id
      LEFT OUTER JOIN vppstation.lane_name l
        ON l.station_id = vrs.station_id
      WHERE vrs.vpp_report_seq_number  = in_report_id;
    -- loop over state history and update information for all stations found
    OPEN station_loop;
    LOOP
      FETCH station_loop
      INTO
            next_station_id,
            next_avi_id,
            next_state_id,
            next_state_eff_date;
      IF station_loop%NOTFOUND THEN
        next_station_id := -1;
        next_avi_id     := -1;
      END IF;
      -- if station/avi has changed take the end of the report period
      IF    (next_station_id <> current_station_id)
         OR (next_avi_id     <> current_avi_id)
      THEN
        period_length := in_time_to - current_state_eff_date;
      ELSE
        -- otherwise the start of the next period marks the end of the current period
        period_length := next_state_eff_date - current_state_eff_date;
      END IF;
      -- if we have a real station id then do some work...
      IF (current_station_id <> -1) THEN
        -- determine which category the period fits to and apply calculation
        IF current_state_id = state_open THEN
          station_open_total := station_open_total + period_length - 1;
        ELSIF current_state_id = state_closed THEN
          station_closed_total := station_closed_total + period_length - 1;
        ELSIF current_state_id = state_all_report THEN
          station_all_report_total := station_all_report_total + period_length - 1;
        ELSE
          RAISE_APPLICATION_ERROR(-20111, 'Error: found unknown state code on avi_state_history - ' || current_state_id );
        END IF;
        -- if the station/avi has changed then commit changes to db
        IF    (next_station_id <> current_station_id)
           OR (next_avi_id     <> current_avi_id)
        THEN
          UPDATE vpproadside.vpp_station_summary
          SET
              station_open       = station_open_total,
              station_close      = station_closed_total,
              station_all_report = station_all_report_total
          WHERE vpp_report_seq_number = in_report_id
          AND   station_id = current_station_id
          AND   ln_number  = current_avi_id;
          -- reset counts
          station_open_total       := 0.0;
          station_closed_total     := 0.0;
          station_all_report_total := 0.0;
        END IF;
      END IF;
      -- if we got past the last record then stop processing
      EXIT WHEN station_loop%NOTFOUND;
      -- if the station/avi is changing, get the state that was 'current' at in_time_from
      IF    (next_station_id <> current_station_id)
         OR (next_avi_id     <> current_avi_id)
      THEN
        current_state_eff_date := in_time_from;
        OPEN entry_state (
               next_station_id,
               next_avi_id,
               in_time_from
        FETCH entry_state
        INTO  current_state_id;
        IF entry_state%NOTFOUND THEN
          current_state_id := state_closed;
        END IF;
        CLOSE entry_state;
        period_length := next_state_eff_date - current_state_eff_date;
        IF current_state_id = state_open THEN
          station_open_total := station_open_total + period_length;
        ELSIF current_state_id = state_closed THEN
          station_closed_total := station_closed_total + period_length;
        ELSIF current_state_id = state_all_report THEN
          station_all_report_total := station_all_report_total + period_length;
        ELSE
            RAISE_APPLICATION_ERROR(-20111, 'Error: found unknown state code on avi_state_history - ' || current_state_id );
        END IF;
      END IF;
      current_state_id       := next_state_id;
      current_state_eff_date := next_state_eff_date;
      current_station_id     := next_station_id;
      current_avi_id         := next_avi_id;
    END LOOP;
    CLOSE station_loop;
    -- update the totals for the percentage calculation
    UPDATE vpproadside.vpp_station_summary
    SET
           station_total = station_open + station_close+ station_all_report
    WHERE   vpp_report_seq_number = in_report_id;
    -- 'fix' the totals that are still zero to avoid divide by zero errors...
    --       note: all the percentages will still come out as zero since the total
    --             was zero
    UPDATE vpproadside.vpp_station_summary
    SET
           station_total = 1.0
    WHERE  vpp_report_seq_number = in_report_id
    AND    station_total = 0.0;
    OPEN result FOR
    SELECT station_name "Site Name",
           lane_name    "Lane Name",
           TO_CHAR((station_open       / station_total) * 100.0, 'FM990.0999') || '%' "Open %",
           TO_CHAR((station_close      / station_total) * 100.0, 'FM990.0999') || '%' "Closed %",
           TO_CHAR((station_all_report / station_total) * 100.0, 'FM990.0999') || '%' "All Report %"
    FROM vpproadside.vpp_station_summary
    WHERE vpp_report_seq_number = in_report_id
    ORDER BY UPPER(station_name),
             UPPER(lane_name);
    DELETE FROM vpproadside.vpp_station_summary
    WHERE vpp_report_seq_number = in_report_id;
    END;Edited by: Indhu Ram on Mar 10, 2010 9:51 AM
    Edited by: Indhu Ram on Mar 10, 2010 9:56 AM
    Edited by: Indhu Ram on Mar 10, 2010 10:58 AM
    Edited by: Indhu Ram on Mar 10, 2010 11:12 AM

    Exactly dont know what you are asking for but I can suggest you some tips here
    - If you want to check the condition in SQL query then you can use CASE statement into select clause i.e.
    SELECT CASE when table1.a=table2.b then table1.c else table2.c END, ... more case..., table columns...
    FROM table1, table2
    WHERE
    <some conditions>
    - If you want to achive same functionality (SELECT only, not UPDATE/INSERT/DELETE) then you can convert the part of same procedure into function and can use the same function into your query by passing the parameters.
    something like this
    SELECT function_name(parameter1, parameter2....) from dual
    Hope this will help

  • Simpler reprsentation to SQL Query is needed

    Hi all,
    I have this SQL Query working goon on the Database but have some errors with Form developer so can anybody simplify it?
         SELECT *
                 FROM (SELECT   COUNT (returned_goods.ID) AS "Max Occurence", products.Name
                           FROM Returned_Goods
                           JOIN Products
                           ON returned_goods.productId = products.Id
                           GROUP BY returned_goods.productId, products.Name
                           ORDER BY COUNT (returned_goods.ID) DESC)
            WHERE ROWNUM = 1;btw, the error encounter me in Forms appears here if anybody can help: [SQL Code not working in Forms Developer without Functions|http://forums.oracle.com/forums/thread.jspa?threadID=842122&tstart=0]
    Thanks in advance :)

    The simpler SQL Staement is
    SELECT *
      FROM (SELECT   COUNT (returned_goods.ID) AS "Max Occurence", products.Name
      FROM returned_goods, products
         WHERE
         Returned_Goods.ProductId = Products.id
             GROUP BY returned_goods.productId, products.Name
             ORDER BY COUNT (returned_goods.ID) DESC)
    WHERE ROWNUM = 1;

  • Lync LcsLog SQL query assistance

    I have this SQL query that we used in the past on LCS and OCS which worked fine.  For Lync it's returning the info I want, but it's also returning all kinds of HTML characters.
    SQL query
    select * from LcsLog.dbo.Messages,LcsLog.dbo.Users where LcsLog.dbo.Users.UserId=Messages.ToId and LcsLog.dbo.Users.UserUri='[email protected]'
    Here's what it returns.  As you can see, all this was just me saying "hello".  How can I remove the html?
    2011-06-04 14:03:19.057    1    2011-06-04 14:03:19.057    1    5    2    2    1    {\rtf1\ansi\ansicpg1252\fromhtml1 \fbidis \deff0{\fonttbl 
    {\f0\fswiss Arial;}  {\f1\fmodern Courier New;}  {\f2\fnil\fcharset2 Symbol;}  {\f3\fmodern\fcharset0 Courier New;}  {\f4\fswiss MS Shell Dlg 2;}}  {\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green0\blue0;}  \uc1\pard\plain\deftab360
    \f0\fs24   {\*\htmltag0 \par }  {\*\htmltag48 <BODY>}{\*\htmltag64}\htmlrtf {\htmlrtf0   {\*\htmltag148 <FONT color=#000000 size=2 face="MS Shell Dlg 2">}\htmlrtf {\cf2 \fs20 \f4 \htmlrtf0   {\*\htmltag4 \par
    }\htmlrtf }\htmlrtf0 {\*\htmltag72}\htmlrtf}\htmlrtf0    {\*\htmltag96 <DIV dir=ltr>}\htmlrtf {\ltrpar\ltrch\ql \htmlrtf0 {\*\htmltag64}\htmlrtf {\htmlrtf0 \htmlrtf {\cf2 \fs20 \f4 \htmlrtf0
    hello\htmlrtf }\htmlrtf0 {\*\htmltag72}\htmlrtf\par}\htmlrtf0    {\*\htmltag104 </DIV>}\htmlrtf }\htmlrtf0   {\*\htmltag248 </FONT>}  {\*\htmltag58 </BODY>}}   
    0    0    0    NULL    NULL    2011-06-17 20:04:42.227    2    [email protected]    0    0
    d

    We are a Microsoft ISV and we have spent a great deal of time reviewing and diving into the lcslog.  In order to help many of our larger enterprise customers, we have built an application specifically to help search, view, and share the conversations
    in the LCSLog database. 
    Of course, you can extract and assemble this content yourself - but you might want to give us a look.  It's possible it that is might save you some time (on the dev front)
    We have a free eval and support both Lync 2010 and Lync 2013 - with a pretty great UI, great performance, and some visual drill down.
    Might save you some time...
    http://www.tryhrauditor.com/
    Peyton

  • Sql query performance need to get improved

    hi all..
    i got performnace issue with my sp where i used 3 cte's.. i'm posting my code.please help me how can i improve the performance of query
    i created non-clustered indexes for tables based on the keys with which the tables are joined..
    USE [OPTM]
    GO
    /****** Object: StoredProcedure [dbo].[GetSample] Script Date: 01/07/2014 10:29:32 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[GetSample]
    @StartDate DateTime,
    @EndDate DateTime,
    @Portfolio int,
    @Program int,
    @Project int
    AS
    Date Author Purpose
    06/11/2012 Ajeesh.C To get the Workitem details for the Scope Workitem Green chart Report.
    06/11/2012 Shinoj.P T-SQL re-structuring.
    Testing :
    exec [dbo].[GetSample] '01/01/2013','12/31/2013',-1,-1,-1
    exec [dbo].[GetSample] '01/01/2013','12/31/2013',16,24,199
    exec [dbo].[GetSample] '11/01/2013','12/31/2013',-1,-1,703
    exec [dbo].[GetSample] '11/01/2012','11/30/2012',8,-1,-1
    select * from tb_Portfolio
    BEGIN
    DECLARE @Scope nvarchar(250),@ScopeID int,@ProjectID int,@WorkItem nvarchar(250),@ProgramID int, @PortfolioID int;
    -------Added 3 columns(StatusID,Status,TaskID)--------
    CREATE TABLE #GrnChartTempTable
    AllocationDate datetime NULL,
    Division nvarchar(50) NULL,
    DivisionID int NULL,
    ResourceName nvarchar(250) NULL,
    ResourceEmailID nvarchar(max) NULL,
    ResourceID int NULL,
    Project nvarchar(250) NULL,
    ProjectID int NULL,
    Scope nvarchar(MAX) NULL,
    ScopeID int NULL,
    WorkItem nvarchar(MAX) NULL,
    TaskStartDate datetime NULL,
    TaskEndDate datetime NULL,
    ProgramID int NULL,
    Program nvarchar(250) NULL,
    PortfolioID int NULL,
    Portfolio nvarchar(250) NULL,
    StatusID int NULL,
    Status nvarchar(50) NULL,
    TaskID int null,
    EstimateHrs nvarchar(250) NULL,
    ScopeEstimateHrs int NULL,
    Allocated int NOT NULL
    WITH Datematrix(AllocationDate)
    As
    SELECT @StartDate AS AllocationDate
    UNION ALL
    SELECT DATEADD(D,1,AllocationDate) AS AllocationDate
    FROM Datematrix WHERE AllocationDate<@EndDate
    Allocation (Division,DivisionID,ResourceName,ResourceEmailID,ResourceID,Project
    ,ProjectID,Scope,ScopeID,WorkItem,TaskStartDate,TaskEndDate
    ,ProgramID ,Program,PortfolioID ,Portfolio,StatusID,Status,TaskID,EstimateHrs,ScopeEstimateHrs)
    AS
    SELECT
    DIV.Division
    ,RES.DivisionID
    ,RES.ResourceName
    ,ResourceEmailID = STUFF((
    SELECT COALESCE( ', ' + CONVERT(VARCHAR,RES.Email1), '')
    FROM dbo.TasksResource TSKRES WITH(NOLOCK) LEFT OUTER JOIN
    dbo.tb_Resource RES WITH(NOLOCK) ON RES.UID = TSKRES.ResourceID
    WHERE TSKRES.TaskID = TSK.TaskID
    FOR XML PATH('')), 1, 1, '')
    ,RES.UID ResourceID
    ,PRJ.Project + ' (' + CONVERT(VARCHAR(15),PRJ.StartDate,101) +' - ' + CONVERT(VARCHAR(15),PRJ.EndDate,101) + ')' as Project
    ,PRJ.UID ProjectID
    ,SCP.Title Scope
    ,SCP.ScopeID
    ,TSK.Title WorkItem
    ,TSK.StartDate TaskStartDate
    ,TSK.EndDate TaskEndDate
    ,PRJ.ProgramID
    ,PR.Program
    ,PR.PortfolioID
    ,PF.Portfolio
    ,TSK.StatusID
    ,ST.Status
    ,TSK.TaskID
    ,TSK.EstimateHrs
    ,(isnull(SCP.EstimateARCH,0) + isnull(SCP.EstimateBA,0) + isnull(SCP.EstimateDev,0) + isnull(SCP.EstimatePM,0) + isnull(SCP.EstimateQA,0) + isnull(SCP.EstimateRM,0)) as ScopeEstimateHrs
    --SCP.EstimateARCH + SCP.EstimateBA +SCP.EstimateDev +SCP.EstimatePM +SCP.EstimateQA +SCP.EstimateRM as ScopeEstimateHrs
    FROM Tasks TSK WITH(NOLOCK)
    INNER JOIN dbo.Scope SCP WITH(NOLOCK) ON TSK.ScopeID = SCP.ScopeID
    INNER JOIN dbo.tb_Project PRJ WITH(NOLOCK)ON TSK.ProjectID = PRJ.UID
    INNER JOIN dbo.tb_Program PR WITH(NOLOCK) ON PR.UID=PRJ.ProgramID
    INNER JOIN dbo.tb_Portfolio PF WITH(NOLOCK)ON PF.UID=PR.PortfolioID
    LEFT OUTER JOIN dbo.TasksResource TSKRES WITH(NOLOCK)ON TSKRES.TaskID = TSK.TaskID
    LEFT OUTER JOIN dbo.tb_Resource RES WITH(NOLOCK) ON RES.UID = TSKRES.ResourceID
    LEFT JOIN dbo.tb_Division DIV WITH(NOLOCK) ON RES.DivisionID = DIV.UID
    LEFT JOIN dbo.tb_Status ST WITH(NOLOCK) ON TSK.StatusID=ST.UID /*relating with the high level work items */
    WHERE (PRJ.UID = @Project OR @Project = -1)
    AND (PRJ.ProgramID = @Program OR @Program = -1)
    AND (PRJ.PortfolioID =@Portfolio OR @Portfolio = -1)
    MainData (AllocationDate,Division,DivisionID,ResourceName,ResourceEmailID,ResourceID,Project,ProjectID
    ,Scope,ScopeID,WorkItem,TaskStartDate,TaskEndDate
    ,ProgramID ,Program,PortfolioID ,Portfolio,StatusID,Status,TaskID,EstimateHrs,ScopeEstimateHrs,Allocated)
    AS
    ( SELECT
    Datematrix.*
    ,Allocation.*
    ,CASE WHEN ISDATE(TaskStartDate)=1 THEN 1 ELSE 0 END AS Allocated
    FROM Datematrix FULL OUTER JOIN Allocation
    ON ( Datematrix.AllocationDate>= Allocation.TaskStartDate
    AND Datematrix.AllocationDate<=Allocation.TaskEndDate
    INSERT INTO #GrnChartTempTable
    SELECT * FROM MainData
    OPTION (MAXRECURSION 0);
    SELECT TOP 1 @Scope=Scope,@ScopeID=ScopeID, @ProjectID=ProjectID
    ,@WorkItem=WorkItem,@ProgramID=ProgramID,@PortfolioID=PortfolioID
    FROM #GrnChartTempTable WHERE Scope IS NOT NULL AND ISDATE(AllocationDate)=1 ORDER BY Scope ;
    SELECT AllocationDate,Division,DivisionID
    ,ResourceName,ResourceEmailID,ResourceID,Project
    ,ISNULL(ProjectID,@ProjectID) ProjectID
    ,ISNULL(Scope,@Scope) Scope
    ,ISNULL(ScopeID,@ScopeID) ScopeID
    ,ISNULL(WorkItem,@WorkItem) WorkItem
    ,TaskStartDate,TaskEndDate
    ,ISNULL(ProgramID ,@ProgramID) ProgramID
    ,Program
    ,ISNULL(PortfolioID,@PortfolioID) PortfolioID
    ,Portfolio,StatusID,Status,TaskID,EstimateHrs,isnull(ScopeEstimateHrs,0)ScopeEstimateHrs,Allocated
    FROM #GrnChartTempTable MainData
    WHERE ISDATE(MainData.AllocationDate)=1
    AND ISNULL(Scope,@Scope) IS NOT NULL
    --WHERE FinalData.Scope IS NOT NULL
    END
    this is my code pls help..
    lucky

    You need to focus on optimizing your code by looking at the logic and removing any extraneous rows that you do not need - stop depending on the optimizer to do your work. 
    You have the following in multiple lines:   ISDATE(AllocationDate)=1
    Look at your final resultset.  You do not want any other rows (where isdate() <> 1) so stop selecting them in the first place. In addition, you are using a full outer join in the first query that uses this logic.  Since you do not qualify
    your columns with the tablename (or alias - which is a best practice), I cannot say if the isdate logic negates the full outer join - but I suspect it might.  I also question the logic behind the assignment of the local variables and their use in the
    final query.  You could remove the separate assignment query (and the variables) by simply moving that query into a derived table (or cte) of the final query.  That might not be a significant improvement (you did not give any indications about the size
    of the various queries) but I think it is simpler, more resilient, more obvious.  I also question the reasoning behind the use of a full outer join.
    Why do you left join to dbo.tb_Status?  Does not every task have a status?
    You join to the TaskResource and tb_Resource tables multiple times (in the Allocation cte) - and it appears that there is a 1/m relationship between task and this joined resultset.  Yet the primary query of the Allocation cte does no aggregation. 
    That is concerning, but I don't know your data so perhaps this is correct.  OTH, perhaps it depends on an assumption and your existing data has not yet violated that assumption. 
    But these are only guesses.  As Erland indicates, optimzing requires knowledge of the tables, the data, your business logic, etc. 

  • Query Assistance Needed - Please

    Monthly Training Table
    >> monthly_training.record_id (int)
    >> , monthly_training.trng_year (int)
    >> , monthly_training.trng_month (int)
    >> , monthly_training.trng_title (varchar)
    >> , monthly_training.trng_code (varchar)
    >> , monthly_training.trng_narrative (longtext)
    Training Completed Table
    >> training_completed.record_id (int)
    >> , training_completed.recorded_by (varchar)
    >> , training_completed.emp_id (varchar)
    >> , training_completed.trng_year (int)
    >> , training_completed.trng_quarter (int)
    >> , training_completed.trng_month (int)
    >> , training_completed.trng_date (date)
    >> , training_completed.trng_category (varchar)
    >> , training_completed.trng_sub_category (varchar)
    >> , training_completed.trng_code (varchar)
    >> , training_completed.trng_start_time (time)
    >> , training_completed.trng_stop_time (time)
    >> , training_completed.trng_hours (decimal)
    DB = MySQL -- CF8
    emp_id = B1200 < stored in cookie at login
    Scenario –
    Monthly Training Table - contains scheduled training for an
    entire year. This training is displayed on a page per the month the
    training should be completed in.
    Training Completed Table – contains the information of
    what training was completed per individual.
    Task At Hand – I would like to display the monthly
    scheduled training for the current year and cross reference the
    completed training table and if the individual has completed the
    training further display something next to the training title, to
    signify completed.
    Example:
    Computer Training – Outlook
    * Off. Dev. – Emergency Scene Safety
    Fire Suppression – Salvage
    I have tried many methods of querying this but have not been
    able to achieve the goal. Perhaps I am making this harder than it
    needs to be. Hopefully someone in the forum can shed some light on
    what I should be doing. Assistance would be greatly appreciated.
    Leonard

    yes, i see it now - the WHERE clause makes sure only
    completed training
    of that employee are selected... my bad - i should have
    changed that
    after you told me that emp_id field was in tc table, not
    mt...
    ok, here we go... this will be a little more complicated...
    try this beast:
    <cfquery name="rs_trng_ck" datasource="#datasource#">
    SELECT mt.trng_title, mt.trng_month, mt.trng_code,
    tcsq.completed
    FROM monthly_training mt
    LEFT JOIN
    (SELECT tc.trng_code AS completed
    FROM training_completed tc
    WHERE tc.emp_id = <cfqueryparam cfsqltype="cf_sql_varchar"
    value="#emp_id#">) AS tcsq
    ON
    mt.trng_code = tcsq.completed
    WHERE mt.trng_year = YEAR(NOW())
    ORDER BY mt.trng_month, mt.trng_title
    </cfquery>
    basically, what this does is uses a sub-query in the FROM
    clause to
    pre-select only those records from tc table where emp_id
    field equals
    the #emp_id# value, and only then left-joins the mt table to
    this
    sub-query recordset, which should result in ALL records from
    mt table
    and only those from tc table where emp_id is correct
    the <cfoutput ...> part shoudl stay the same as before.
    hope this one works :)
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Tweak for sql query - help needed for smalll change

    Hi.
    I am trying to run a script that checks for used space on all tablespaces and returns the results.
    So far so good:
    set lines 200 pages 2000
    col tablespace_name heading 'Tablespace' format a30 truncate
    col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    col used_space_mb heading 'MB|Used' format 9G999G999D99
    col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    col pct_used heading '%|Used' format 999D99
    col pct_free heading '%|Free' like pct_used
    break on report
    compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    select
    alloc.tablespace_name,
    (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    free.free_space_mb free_space_ext_mb,
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    FROM (SELECT tablespace_name,
    ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    ROUND(SUM(bytes)/1048576) total_allocspace_mb
    FROM dba_data_files
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) alloc,
    (SELECT tablespace_name,
    SUM(bytes)/1048576 free_space_mb
    FROM dba_free_space
    WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    GROUP BY tablespace_name) free
    WHERE alloc.tablespace_name = free.tablespace_name (+)
    ORDER BY pct_used DESC
    The above returns something like this:
    MB MB % %
    Tablespace Used Free Till Ext Used Free
    APPS_TS_ARCHIVE 1,993.13 54.88 97.32 2.68
    APPS_TS_TX_IDX 14,756.13 1,086.88 91.37 8.63
    APPS_TS_TX_DATA 20,525.75 594.25 80.18 19.82
    APPS_TS_MEDIA 6,092.00 180.00 74.37 25.63
    APPS_TS_INTERFACE 13,177.63 366.38 71.49 28.51
    The above works fine, but I would like to further change the query so that only those tablespaces with free space less than 5% (or used space more than 95%) are returned.
    I have been working on this all morning and wanted to open it up to the masters!
    I have tried using WHERE pct_used > 95 but to no avail.
    Any advice would be appreciated.
    Many thanks.
    10.2.0.4
    Linux Red Hat 4.

    Thanks for that.
    What is confusing is that the below query works for every other (about 10 others) database but not this one (?)
    SQL> set lines 200 pages 2000
    SQL>
    SQL> col tablespace_name heading 'Tablespace' format a30 truncate
    SQL> col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
    SQL> col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
    SQL> col used_space_mb heading 'MB|Used' format 9G999G999D99
    SQL> col free_space_mb heading 'MB|Free Till Max' like used_space_mb
    SQL> col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
    SQL> col pct_used heading '%|Used' format 999D99
    SQL> col pct_free heading '%|Free' like pct_used
    SQL>
    SQL> break on report
    SQL> compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
    SQL>
    SQL> select /*+ALL_ROWS */
    2 alloc.tablespace_name,
    3 alloc.total_maxspace_mb,
    4 alloc.total_allocspace_mb,
    5 (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
    6 free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb) free_space_mb,
    7 free.free_space_mb free_space_ext_mb,
    8 ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    9 ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
    10 FROM (SELECT tablespace_name,
    11 ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
    12 ROUND(SUM(bytes)/1048576) total_allocspace_mb
    13 FROM dba_data_files
    14 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    15 GROUP BY tablespace_name) alloc,
    16 (SELECT tablespace_name,
    17 SUM(bytes)/1048576 free_space_mb
    18 FROM dba_free_space
    19 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
    20 GROUP BY tablespace_name) free
    21 WHERE alloc.tablespace_name = free.tablespace_name (+)
    22 ORDER BY pct_used DESC
    23 /
    ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
    ERROR at line 8:
    ORA-01476: divisor is equal to zero

  • Different Result for SQL and PL/SQL query..need a bit of help

    If i just run:
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    It works great.
    If I run
    BEGIN
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    END
    I get the following error.
    ORA-04052: error occurred when looking up remote object [email protected]
    ORA-00604: error occurred at recursive SQL level 3
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-488: invalid variable declaration: object 'NUMBER' must be a type or subtype
    ORA-02063: preceding 2 lines from SMGLINK

    Hi,
    Whenever you have a problem, post a complete test script that people can run to re-create the problem and test their ideas. Include CREATE TABLE and INSERT statements for any or your own tables needed.
    Post the results you want from that sample data.
    Always say which version of Oracle you're using.
    bostonmacosx wrote:
    If i just run:
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';If OPEN_TIME is a DATE, then don't try to compare it to a string, such as '1/1/2011'. (This is not related to the present problem, only a future one.)
    It works great.
    If I run
    BEGIN
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    END
    I get the following error.
    ORA-04052: error occurred when looking up remote object [email protected]
    ORA-00604: error occurred at recursive SQL level 3
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-488: invalid variable declaration: object 'NUMBER' must be a type or subtype
    ORA-02063: preceding 2 lines from SMGLINKI would expect a different error "PLS_00428: an INTO clause is expected".

  • Query assistance needed

    Hi experts,
    I am trying below query to find out all columns which are present more than once i.e which are all common in tables.
    select a.column_name,b.table_name from
    (select column_name, count(*) from sys.all_tab_columns
    group by column_name
    having count(*)>1) a, sys.all_tab_columns b
    where
    a.column_name=b.column_name
    and owner = 'CP'
    order by a.column_name i am getting results.. but i require result something like below:
    column_name    Table_name
    col1           Table1   
                   Table2
    col2           Table1
                   Table4
    col3           Table1
                   Table2
                   Table4Regards
    asp

    select  case row_number() over(partition by a.column_name order by b.table_name)
              when 1 then a.column_name
            end column_name,
            b.table_name
      from (
            select  column_name,
                    count(*)
              from  sys.all_tab_columns
              group by column_name
              having count(*)>1
           ) a,
           sys.all_tab_columns b
      where a.column_name=b.column_name
        and owner = 'CP'
      order by a.column_name,
               b.table_name
    /For example:
    SQL> select  case row_number() over(partition by a.column_name order by b.table_name)
      2            when 1 then a.column_name
      3          end column_name,
      4          b.table_name
      5    from (
      6          select  column_name,
      7                  count(*)
      8            from  sys.all_tab_columns
      9            group by column_name
    10            having count(*)>1
    11         ) a,
    12         sys.all_tab_columns b
    13    where a.column_name=b.column_name
    14      and owner = 'SCOTT'
    15    order by a.column_name,
    16             b.table_name
    17  /
    COLUMN_NAME                    TABLE_NAME
    ACTIVE                         PRODUCTS
                                   TBL_ERRLOG
    ADDRESS                        ADDRESSBOOK_EXT
    ADJ_SALARY                     TESTME
                                   TESTME2
    ARTNO                          ARTICLE
                                   MUTATIONS
    ATTRIBUTE1                     TYPE2_TABLE
    CHANGE_VECTOR$$                MLOG$_EMP
                                   RUPD$_EMPSY.

  • A Oracle sql query is needed, please help me out

    Hi,
    I have a table similar to scott.emp table and i should get first three recently joined employees salaries according to their joined date from each deptno
    output should like this:
    deptno firstempsalary secondemplsal thirdemploysalary
    10 xxx xxx xxxx
    20 xx xx
    30 xx xxx xxxx
    40 xx
    50 xx xxxx xxx
    60 xx xx
    70 xx
    it means that 70 dept having only one employee and 20 dept having only two employees and 10 dept having more than three employees but we should get only three recently joined employees salaries from 10 dept.
    Hope this is clear .. please give me a query to get this info ..
    oracle is 10g version
    great thanks in advance.

    select deptno,
    max(case jd_rank when 1 then salary end) firstempsal,
    max(case jd_rank when 2 then salary end) secondempsal,
    max(case jd_rank when 3 then salary end) thirdempsal
    from
    (select salary, deptno, row_number() over(partition by deptno order by join_date desc) jd_rank from emp)
    group by deptno
    Problem here is what to do when employees have the same join date? This example will arbitrarily choose their order and if, for example, three employees share the same (most recent) join date then they will arbitrarily be classed as "first", "second" and "third". If four employees join at the same time, one of them will be ignored at random!
    Edited by: user10548434 on 03-Dec-2008 06:27

  • SAP B1 Query - assistance needed

    Dear Experts,
    We are working on cash flow forecasting model, i.e going forward 12 months, which in written in MS Excel. We update it with actual data recorded in SAP B1 (Ver 8.8 PL18)  A manual process.
    Was wondering if we can get a single query written which will provide the following data:
    Sales and Purchases by BP in a given time (user specified)
    BP Code
    BP Name
    Type of Document (i.e invoice. credit memo)
    Date of the document
    The value of the document (Gross including any taxes)
    Collections and Payments of to/from BP in a given time (user specified)
    BP Code
    BP Name
    Document Type (i.e receipt or payment)
    Document number the reciept or payment is related to to i.e the invoice that is being paid or receipted
    Date pf payment/receipt
    Amount
    Thank you in advance.
    Regards
    Raj

    Hi,
    Try this:
    SELECT distinct T0.[CardCode], T0.[CardName], T0.[DocNum] as Invoice#, T0.[DocDate], T0.[DocTotal], T3.[DocNum] as Credit#, T3.[DocDate], T3.[DocTotal] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry left join  RIN1 T2 on  T2.[BaseEntry]  = t0.docentry and  T2.[BaseLine]  =  T1.[LineNum] left JOIN ORIN T3 ON T2.DocEntry = T3.DocEntry WHERE T0.[DocDate] between [%0] and [%1]
    2. It is not possible to get invoices in single query.
    Advice, your sales and purchase process to understand and write query.
    Thanks & Regards,
    Nagarajan

Maybe you are looking for