Using correlated sub-query in update stmt

Hi,
I just need a help to fine tune this below query. The following query is throwng connection reset error.
UPDATE ftmmgr.RECON_TEMP RT SET PRCS_STAT_F =
(CASE WHEN (SELECT COUNT(1) as count FROM ftmmgr.INVC_ITEM ii WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I) =
(SELECT COUNT(1) as count FROM ftmmgr.RECON_TEMP rtr WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I AND
UPPER(TRIM(SLF_RECON_F)) = 'N' AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
THEN 'F' ELSE 'O' END)
Thanks in advance

vasanthskr wrote:
Hi,
I just need a help to fine tune this below query. The following query is throwng connection reset error.
UPDATE ftmmgr.RECON_TEMP RT SET PRCS_STAT_F =
(CASE WHEN (SELECT COUNT(1) as count FROM ftmmgr.INVC_ITEM ii WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I) =
(SELECT COUNT(1) as count FROM ftmmgr.RECON_TEMP rtr WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I AND
UPPER(TRIM(SLF_RECON_F)) = 'N' AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
THEN 'F' ELSE 'O' END)
Thanks in advanceNo database version provided?
No table structures povided?
No example data provided?
No explanation as to what you're trying to achieve?
As for tuning....
No explain plans provided?
No trace provided?
No details of indexes or statistics, cardinality, selectivity or skew of data provided?
Read these threads:
[How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
[When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
It's also a good idea to provide a nicely formatted version of your code so people can read it, using {noformat}{noformat} tags around it...UPDATE ftmmgr.RECON_TEMP RT
SET PRCS_STAT_F =
(CASE WHEN (SELECT COUNT(1) as count
FROM ftmmgr.INVC_ITEM ii
WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I)
=
(SELECT COUNT(1) as count
FROM ftmmgr.RECON_TEMP rtr
WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I
AND UPPER(TRIM(SLF_RECON_F)) = 'N'
AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
THEN 'F'
ELSE 'O'
END)

Similar Messages

  • CORRELATED SUB QUERY IN OBIEE

    Hi Experts,
    How to achieve correlated sub query in OBIEE
    Example for correlated sub query is here:
    SELECT
    HR_EMPLOYEE_DIM.EMPLID,
    HR_EMPLOYEE_DIM.NAME,
    HR_EMPLOYEE_DIM.JOBCODE_CD,
    HR_EMPLOYEE_DIM.JOBCODE_DESC,
    FROM
    HR_EMPLOYEE_DIM,
    EMPLOYEE_ACTION_FACT
    WHERE
    ( EMPLOYEE_ACTION_FACT.HR_EMPLOYEE_KEY=HR_EMPLOYEE_DIM.HR_EMPLOYEE_KEY )
    AND
    ( to_char(EMPLOYEE_ACTION_FACT.PS_EFF_DT,'yyyymmdd') || EMPLOYEE_ACTION_FACT.PS_EFF_SEQ=
    (SELECT MAX(TO_CHAR(PS_EFF_DT,'yyyymmdd')|| PS_EFF_SEQ)
    FROM
    EMPLOYEE_ACTION_FACT EAF1,
    HR_EMPLOYEE_DIM HED1
    WHERE EAF1.HR_EMPLOYEE_KEY = HED1.HR_EMPLOYEE_KEY
    AND HED1.PS_EMPLID = HR_EMPLOYEE_DIM.PS_EMPLID
    Thanks
    Naresh
    Edited by: Naresh Meda on Dec 2, 2008 5:52 AM

    But I want to pass presentation variable for the second query.
    Regards
    Naresh
    Edited by: Naresh Meda on Dec 2, 2008 10:27 PM

  • Use of Sub Query in a filter is throwing error

    Hi
    I am using a sub query in a filter which throws me the following error in owb 9i.
    PLS 00405 : Subquery cannot be used in this context.
    But the use of subquery works fine in a joiner operator.
    Use of Sub Query in a filter works fine in owb 2i.
    Could any one please help me.
    Thanks in Advance
    Nanda Kishore

    Nanda,
    Please wrap the source table in a view containing the subquery and then use the view as a source rather than use the subquery in the filter.
    Regards:
    Igor

  • Correlated Sub Query

    Deal All,
    Please help me to know list of Drawback/Limitation of Corellated Subquery.
    i want to Optimize the correlated sub Query.
    Thanks,
    Dinesh Babu
    9818783322

    See:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3167884300346662300
    It would be nice to know your database version.
    It would be nice to know what query you're executing
    It would be nice to see an execution plan
    It would be nice if you'd first read the SQL and PL/SQL FAQ, especially:
    SQL and PL/SQL FAQ
    and
    *3. How to improve the performance of my query? / My query is running slow*.
    When your query takes too long...
    How to post a SQL statement tuning request
    SQL and PL/SQL FAQ

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Need help in correlated sub query logic

    Hi ,
    I have one procedure with cursor. I have given small part of the cursor as shown below .
    SELECT
      A.DAY_DATE,
      A.COUNTRY_CODE,
      A.INST_CODE,
      a.bra_code,
      a.cus_num,
      a.cur_code,
      a.led_code,
      a.sub_acct_code,
      (tra_amt * SPOT_RATE) pre_day_crnt_bal,
      t.mat_date,
      t.NEW_INT_RATE int_rate,
      t.DEB_CRE_IND int_chg_pai_ind,
      a.ACCT_TYPE,
      (SELECT COUNT (
      DISTINCT TO_CHAR (day_date, 'mm')
      FROM PIO_TIMES
      WHERE day_date BETWEEN a.day_date
      AND NVL ( T.MAT_DATE,A.DAY_DATE) 
      AND TO_CHAR (day_date, 'dd') = '31') Test
    Here how can I build the logic for inside select statement.
    I tried to build the separate stream for the inside select statement but I am confusing how to handle the count in the inside the query.
    Please help me how to build the logic for the inside query statement .
    Thanks & Regards,
    Ramana.

    Hi Balakrishna,
    Thanks for your support
    I have applied but I am not getting the column in the output columns from the custom sql function.
    As per the procedure we are using the all conditions like between and month or date conditions  to find the count of distinct months.
    If we use partial conditional in the custom SQL  and partial conditionals in the lookup condition clause is it give the same result?
    How can we get the field of custom sql in the output field.
    Thanks & Regards,
    Ramana.

  • Give the query  for  this requirement can we get it in correlated sub query

    i have to query avg(someinfo) group by dayofthemonth for last three days
    select someinfo from
    (select avg(someinfo)from table tab
    group by dayofdate1
    where exists(select * from table
    having max(date1)-tab.date1<3 )
    how can we group day of the date1
    someinfo date1
    10 28-jun-2006
    20 28-jun-2006
    30 29-jun-2006
    30 29-jun-2006
    10 30-jun-2006
    20 30-jun-2006
    30 1-july-2006
    40 1-july-2006
    30 2-july-2006
    40 2-july-2006
    i have to query avg(someinfo) group by day for last three days
    avg(someinfo) date1
    35 2-jun-2006
    35 1-july-2006
    15 30-june-2006
    here no need of union
    Message was edited by:
    user517983
    Message was edited by:
    user517983
    Message was edited by:
    user517983
    Message was edited by:
    user517983

    SQL> CREATE TABLE t_table
      2  AS
      3 (SELECT 10 day ,'28-jun-2006' ft FROM dual
      4  UNION
      5  SELECT 20,'28-jun-2006' FROM dual
      6  UNION
      7  SELECT 30,'29-jun-2006' FROM dual
      8  UNION
      9  SELECT 30,'29-jun-2006' FROM dual
    10  UNION
    11  SELECT 10,'30-jun-2006' FROM dual
    12  UNION
    13  SELECT 20,'30-jun-2006' FROM dual
    14  UNION
    15  SELECT 30,'1-jul-2006' FROM dual
    16  UNION
    17  SELECT 40,'1-jul-2006' FROM dual
    18  UNION
    19  SELECT 30,'2-jul-2006' FROM dual
    20  UNION
    21  SELECT 40,'2-jul-2006' FROM dual)
    22  .
    SQL> /
    Table created.
    SQL> DESC t_table
    Name                                                  Null?    Type
    DAY                                                            NUMBER
    FT                                                             VARCHAR2(11)
    SQL> SELECT * FROM t_table;
           DAY FT
            10 28-jun-2006
            10 30-jun-2006
            20 28-jun-2006
            20 30-jun-2006
            30 1-jul-2006
            30 2-jul-2006
            30 29-jun-2006
            40 1-jul-2006
            40 2-jul-2006
    9 rows selected.
    SQL> SELECT day,ft FROM (SELECT AVG(day) day,ft FROM t_table GROUP BY ft ORDER BY ft DESC)
      2  WHERE ROWNUM<=3;
           DAY FT
            15 30-jun-2006
            30 29-jun-2006
            15 28-jun-2006Khurram

  • Query to update a table

    Hi my requirement is like this:
    col1 col2 col3 col4 col5
    1 1 12 21
    1 1 13 23
    1 2 12 23
    1 2 12 24
    1 2 13 25
    I want the column5 to be popluated with col4 value, the condtions are
    col3=13 and group by col1,col2
    i.e the final table shud be:
    col1 col2 col3 col4 col5
    1 1 12 21 23
    1 1 13 23 23
    1 2 12 23 25
    1 2 12 24 25
    1 2 13 25 25
    please help me with the query..
    does simple sql works or shud i go pl/sql
    if possible plz help me with the code..
    as i need it urgently.
    thank you

    Hi,
    You don't need PL/SQL; you can do that with a correlated sub-query:
    UPDATE   table_x  m   -- m for main
    SET     col5 =
            SELECT  MAX (col4)
            FROM    table_x
            WHERE   col1 = m.col1
            AND     col2 = m.col2
            AND     col3 = 13
    ;If some group has more than one col3=13, then this will still work, using the greatest col4 from those rows.

  • Urgent - Cannot run sub query from VB 6

    Hello!
    I'm having a problem with my Oracle OLE DB connection in windows using Visual Basic 6.0 SP3.
    I can run normal queries just fine, but a correlated sub query like this:
    select A.col_a, (select col_b from Tab_B where id = A.id) from Tab_A A
    returns the following error:
    "ORA-00907: missing right parenthesis"
    But I'm able to run the query witout errors in Toad with the correct result!
    So basically, I cannot run a (correlated?) sub query via OLE DB...
    What am I doing wrong?? Is it a parameter that I need to set on the connection of command?
    I'm not using stored procedures, only plain text SQL.
    Very thankful for a quick answer, this is really urgent. If you have the possibility, please e-mail me at:
    [email protected]
    Thank you in advance.
    Best regards,
    Bnar Baban

    Hi!
    I'm running the latest version of Oracle OLE DB...when checking more in detail, it seems that the provider parses the code in a way, that makes the "(select" part of the sub statement be interpreted as a column name....when it does not find a right parenthesis, but a white space, it complains.
    I switched to Microsoft MSDAORA provider, and now it works perfectly...
    /Bnar

  • Calculation based on sub query

    Is it possible to base a calculation on a sub query whereby both the calculation sheet and sub query sheet reside on same discoverer workbook?
    This is possible in MS Excel whereby information from one tab can be used in another tab. I am using Discoverer 3.1.44

    Hi
    I'm afraid that Discoverer's use of sub queries is restricted to only using a sub query as a means of further controlling the data that is pulled back.
    It is not possible to use data from a sub query in a calculation, only in a condition. It also makes no difference which version of Discoverer you have because this mode of operation remains the same no matter what version you have (even 10g!!)
    Hope this helps
    Regards
    Michael

  • Queerish behavior of 'IN' sub query

    Hii all,
    I've encountered strange behavior of in clause.Here I'm providing a test case.
    SQL> Create table r_dummy_1
      2  as select object_name from user_objects
      3  where rownum <= 10
      4  ;
    Table created.
    SQL> select object_name from r_dummy_1;
    OBJECT_NAME
    CP_ST_CRITERIA
    CP_ST_EXPENSE_CODE
    CP_ST_FACILITIES
    CP_ST_FACILITY_INFO
    CP_ST_FAC_RESULT
    CP_ST_INSTR_RESULT
    CP_ST_RATINGS
    CP_ST_RESULT_SET_DATE
    CP_ST_RLTNSP_NAME
    CP_ST_SIC_CODES
    10 rows selected.I don't have a column named 'NAME' in my table 'R_DUMMY_1'.
    But....
    select *
    from user_source
    where name in(
                           select name
                           from r_dummy_1
                 )This query runs fine !!!!!!!!!!!!!!!
    And when I individually run the inner query
    SQL>  select name
      2                         from r_dummy_1;
    select name
    ERROR at line 1:
    ORA-00904: "NAME": invalid identifierIs this is a bug??

    Hi,
    RGH wrote:
    I thought the inner query executes first(Unlike correlated sub queries) and the outer picks the name matching in the result set.The optimizer decides whether the sub-query gets executed first or not.
    Consider this query:
    SELECT  *
    FROM    scott.emp
    WHERE   1 = 2
    AND     deptno  IN (SELECT ...)
    ;The sub-query may not be run at all, because the optimizer "short-circuits". That is, it sees that the WHERE clause will resolve to FALSE regardless of what the sub-query produces, so it won't waste time running the sub-query.
    Most of the time, assuming the sub-query is run, the results are as if the siub-query gets executed first, but in a correlated sub-query, at least part of the parent query has to be done earlier, because the values referenced in the sub-query have to be fetched before the sub-query can complete.
    So in your query
    select *
    from user_source
    where name in(
                           select name
                           from r_dummy_1
                 )The main query has to decide whether or not to include a row (let's say it's a row where name='PROC_X') from user_source, so it runs the sub-query. The sub-query runs, and produces a result set that includes the name from the main query, 'PROC_X'; control returns to the main query, and it compares the name to the results of the sub-query. The net effect is the same as:
    select *
    from user_source
    where name in(name)For all I know, the optimizer may realize this, and re-write the query to actually perform the second version, never touchiung r_dummy_1 at all.

  • A SIMPLE Sub query.

    A simple sub query
    I have a table called instrument with a field called id_inst
    instrument
    id_inst
    0000203
    There is another table called instrument_xref
    instrument_xref
    id_inst id_inst_xref
    0000203 890000
    I want to use a sub query that will give the output
    id_inst  id_inst_xref
    0000203  890000
    The subquery I am using is not working
    Select i.id_inst,insx.id_inst_xref
    from instrument i,instrument_xref insx
    where i.id_inst = (Select ???
    Can some one please help?

    You don't need a subquery :
    SQL> Select i.id_inst,insx.id_inst_xref
      2  from instrument i,instrument_xref insx
      3* where i.id_inst = insx.id_inst;anyway :
    SQL> Select i.id_inst,insx.id_inst_xref
      2  from instrument i,instrument_xref insx
      3* where i.id_inst = (select id_inst from instrument_xref);

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

  • Sub-query question, looking up value within a query

    I have a situation to lookup prior period value within the same query. I tried to use a sub-query but getting a syntax error:
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1, 
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD, [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS, [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT, [VALUE-BAND_ACCT].ARPSn_ACCT,
    [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    (SELECT [VALUE-BAND_ACCT].COMB_VALUE_BAND
     FROM VALUE-BAND_ACCT
     WHERE [VALUE-BAND_ACCT].PERIOD = DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)) AS PRIOR_VALUE_BAND
    FROM VALUE-BAND_ACCT;
    Appreciating help.

    Try this:
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1,
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD,
    [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS,
    [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT,
    [VALUE-BAND_ACCT].ARPSn_ACCT, [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    [VALUE-BAND_ACCT_1].COMB_VALUE_BAND AS PRIOR_VALUE_BAND
    FROM [VALUE-BAND_ACCT] INNER JOIN [VALUE-BAND_ACCT] AS [VALUE-BAND_ACCT_1]
    ON [VALUE-BAND_ACCT].GLSeq = [VALUE-BAND_ACCT_1].GLSeq AND
    [VALUE-BAND_ACCT].[LOB$] = [VALUE-BAND_ACCT_1].[LOB$]
    WHERE [VALUE-BAND_ACCT_1].PERIOD =
    DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)
    or
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1,
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD,
    [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS,
    [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT,
    [VALUE-BAND_ACCT].ARPSn_ACCT, [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    [VALUE-BAND_ACCT_1].COMB_VALUE_BAND AS PRIOR_VALUE_BAND
    FROM [VALUE-BAND_ACCT] INNER JOIN [VALUE-BAND_ACCT] AS [VALUE-BAND_ACCT_1]
    ON [VALUE-BAND_ACCT].GLSeq = [VALUE-BAND_ACCT_1].GLSeq AND
    [VALUE-BAND_ACCT].[LOB$] = [VALUE-BAND_ACCT_1].[LOB$] AND
    [VALUE-BAND_ACCT_1].PERIOD =
    DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • How to use sub query in CAML in splist

    hi,
    want to know whether any sub query functionality can be achieved in splist/sp doc lib using  CAML designer 2013/ query builder. also inner joins need to be implemented as pe rmy requirement.
    if caml designer is not supported, whats the allternative way of doing this?
    can LINQ to SP be used? if yes, can anyone pls roivde how to implement  the same
     help is appreciated

    You can use the let keyword to scope a variable containing the result of your subquery.
     However, it depends on the LINQ provider as to whether or not it can understand the command.
    For example, you can create the sample like this
    var result = (from p in productInQuery
          join o in orderInfoQuery on p.refNo equals o.refNo
          join t in productOutQuery on p.no equals t.productInNo into productIn
          from t in productIn.DefaultIfEmpty()
          let dateOut = (from m in orderInfoQuery where m.refNo == t.refNo select m.processData).FirstOrDefault()
          orderby o.processDate descending
          select new
              modelNo = x.modelNo,
              qty = p.qty,
              dateIn = o.processDate,
              dateOut = dateOut
    https://www.youtube.com/watch?v=N3K0h6GDwW4
    For more info, check this
    http://msdn.microsoft.com/en-us/library/ee539975.aspx

Maybe you are looking for

  • My Mobile me mail account is unreliable now that i have moved to the cloud

    I have had a @me mail account form the start and before that a @mac account, but now that the iCloud has arrived accessing my mail through Outlook has become totally unrealable, at first i thought it was an Outlook issue, spent days verifying that Ou

  • Web pages loading slowly or not at all in all browsers

    I don't know why I'm having this problem.... for the last few weeks now.    95% of the time, web pages (for me.... particularly in Ancestry.com and Ebay) load very slowly, or don't load at all.  The other 5% of the time, it appears to work normally. 

  • Fetch from bseg

    Hi, I have a requiremet to get the g/l account from BSEG table and this too by connecting purchase doc no. Put ebeln in bseg and get the g/l accounts. This prcess I want to do for a large volume of data at a time. Since the search is without keyfield

  • Batch No. within Outgoing Excise Invoice

    Dear All,          How can I get Batch No. of the Items within Outgoing Excise Invoice. Regards Hitesh Parsawala

  • User Exit RFKORIEX for f.27

    Hello Experts, Please help me.... I have used RFKORIEX user Exit for Sending Email for Customer Account, It is working Successfully but the problem which i am facing is that if i am commenting my coding which is as given below: SELECT SINGLE * FROM a