Help in the below query

Hi ,
I have the following string
select '1, ,3, , , abc, ,dce,234, , , abc 1 ,1 ,4 ' from dual
and i have translations for
abc,dce and abc 1 respecitvely as
X ,Y and Z
which i strore in a table as
1 abc X
2 dce Y
3 abc 1 Z
now i want to replace these tranlations in my original string such that my spaces etc are intact ( note that i cannot use the replace function directly)
MY final string should look like
1, ,3, , , X, ,Y,234, , , Z ,1 ,4
any pointers how i can achieve it.
Thanks

Prazy wrote:
Aketi Jyuuzou wrote:
I like recursive with clause B-)Yes but recursive with clause is being supported only from 11gR2 but OP is using *10gR2* B-)Hehe I was to start create SQL seeing OP's first Post only :-)
And I prefer recursive with clause than model clause B-)
And my prev SQL is wrong.
with t as(
select '1, ,3, , , abc, ,dce,234, , , abc 1 ,1 ,4 '
as str from dual),
repstr(ID,befo,aft) as(
select 1,'abc','X' from dual union
select 2,'dce','Y' from dual union
select 3,'abc 1','Z' from dual),
rec(str,LV) as(
select RegExp_Replace(a.str,
       '(,|^)( *)' || b.befo || '( *)(,|$)',
       '\1\2' || b.aft || '\3\4'),1
  from t a,repstr b
where b.ID=1
union all
select RegExp_Replace(a.str,
       '(,|^)( *)' || b.befo || '( *)(,|$)',
       '\1\2' || b.aft || '\3\4'),a.LV+1
  from rec a,repstr b
where a.LV+1 = b.ID)
select max(str) Keep(Dense_Rank Last order by LV) as str
  from rec;
STR
1, ,3, , , X, ,Y,234, , , Z ,1 ,4

Similar Messages

  • Need help on the below query.

    Hi All,
    I've a query given below..
    SELECT W.WONUM,
         W.STATUS,
         WS.CHANGEDATE,
         EH.OLD_RATE
         FROM
         WORKORDER W,
         WOSTATUS WS,
         ESTIMATE_HEADER@GQMFOF EH
    WHERE WS.CHANGEDATE BETWEEN '01-Oct-2009' AND '1-Nov-2009'
    AND W.WONUM = WS.WONUM
    AND EH.OLD_RATE = 'N'
    AND WS.WOSTATUS = 'CLOSE';
    I would like to get All the data which status =closed in the month of Oct for Old rate,
    So for this i am writing the query above. But not getting the o/p.
    It is giving me that " Table/View doesn't exist.
    There 2 schemas MAXIMO,GQMMGR..
    DBlinks are GQMFOF,MAXFOFNC..
    Can anyone help me while writing the above query...
    Regards,
    gr.

    A question was asked in your other thread. But the problem was you dint care to give an answer.
    Dont open duplicate post.
    I need help on the below problem..

  • Need help on the below query or Pl-SQL

    Hello Every one,
    Please let me know if some one can help me out with the below scenario either in pl-sql or sql.
    Source Data:
    0000253800     0.25          0845A     0900A
    0000253800     1          0900A     1000A
    0000253800     1          1300P     1400P
    0000253800     1          1500P     1600P
    0000253800     1          1600P     1700P
    Output needed:
    0000253800     1.25          0845A     1000A
    0000253800     1          1300P     1400P
    0000253800     2          1500P     1700P
    Thanks in Advance....
    Edited by: user12564103 on Dec 11, 2011 5:54 PM

    Hi,
    Welcome to the forum!
    Depending on your data and your requirements:
    WITH     got_times     AS
         SELECT     column_1, column_2, column_3, column_4
         ,     TO_DATE ( substr (column_3, 1, 4)
                   , 'HH24MI'
                   )     AS time_3
         ,     TO_DATE ( SUBSTR (column_4, 1, 4)
                   , 'HH24MI'
                   )     AS time_4
         FROM     table_x
    ,     got_grp_id     AS
         SELECT     column_1, column_2, column_3, column_4
         ,     time_3, time_4
         ,     time_4 - SUM (time_4 - time_3) OVER ( PARTITION BY  column_1
                                        ORDER BY         time_3
                                      )     AS grp_id
         FROM     got_times
    SELECT       column_1
    ,       SUM (column_2)     AS sum_2
    ,       MIN (column_3) KEEP (DENSE_RANK FIRST ORDER BY time_3)
                        AS min_3
    ,       MAX (column_4) KEEP (DENSE_RANK LAST  ORDER BY time_4)
                        AS max_4
    FROM       got_grp_id
    GROUP BY  column_1
    ,       grp_id
    ORDER BY  column_1
    ,       grp_id
    ;Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, as well as the results you want from that data. Explain, with specific examples, how you get the results you want from that data.
    Always say which version of Oracle you're using. The query above will work in Oracle 9.1 (and higher).
    Since this is your first thread, I'll do this for you:
    CREATE TABLE     table_x
    (     column_1     NUMBER
    ,     column_2     NUMBER
    ,     column_3     VARCHAR2 (5)
    ,     column_4     VARCHAR2 (5)
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, .25, '0845A', '0900A');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '0900A', '1000A');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1300P', '1400P');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1500P', '1600P');
    INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1600P', '1700P');Column_1 identifes a day.
    Column_2 is an amount that I need to total.
    Column_3 and column_4 are starting and ending times. We can assume that they are all valid times (in 'HH24MI' format, plus a redundant 'A' or 'P') on the same day, column_3 is always less than column_4, and that the range of two rows for the same value of column_1 never overlap. Column_4 of one row may be equal to column_3 of another rows with the same column_1, but it will never be greater.
    Each row of the output represent a contiguous group of rows (each ending exactly when the next one begins) with the same column_1, with the common column_1, the total of column_2, and the range of the group.
    For example, the first two rows for a single group, because they have the same value for column_1, and one ends exactly when the other begins (at 9:00 AM). This group represents day 253800, from 8:45 AM to 10:00 AM. The totla of column_2 fro this group is .25 + 1 = 1.25.
    The next row (from 1:00 PM to 2:00 PM) is a group all by itself, because there is a gap one either side of it separating it from its nearest neighbor on the same day."
    Of course, I'm guessing at lots of things.
    Edited by: Frank Kulash on Dec 11, 2011 9:44 PM
    Changed TO_DATE calls.
    Edited by: Frank Kulash on Dec 11, 2011 9:52 PM
    Added sample question.

  • Need Help with the below query

    Hi All,
    I'm working on Oracle HRMS tables which have date tracking facility.
    I'm working on Oracle 10G.
    I have a table per_all_assignments_f(seeded) which contains the employee related information.
    It has normal hours and the assignment_id(primary key) in the table
    The data is something like
    assignment_id     
    123                   30                   01-Jan-2000               31-dec-2009
    123                    32                 01-Jan-2010               31-dec-2012
    123                  
    assignment_id
    Normal_hours
    Effective_start_Date
    Effective_end_Date
    123    
    30
    01-Jan-2000
    31-dec-2009
    123
    32
    01-Jan-2010
    31-dec-2012
    123
    40
    01-Jan-20103
    40                  01-jan-2013               31-dec-4712
    Now I'd like to pass the latest date(sysdate) to a function which should give me the
    last changed normal hours as on today. In this case 32.
    select normal_hours from per_all_assignments_f where
    assignment_id=123
    and trunc(latest_date) between effective_start_date and effective_end_date
    This will give me the latest normal hours of 40 but I want the last changed hours irrespective of how many ever be the changes.
    hope I'm clear in specifying my requirement.
    Appreciate your time
    Thanks,
    AJ

    877722 wrote:
    It has normal hours and the assignment_id(primary key) in the table
    How PK value is repeating in your sample data!
    877722 wrote:
    This will give me the latest normal hours of 40 but I want the last changed hours irrespective of how many ever be the changes.
    hope I'm clear in specifying my requirement.
    Nope. What is "changed hours"? Not able to break your source code!  a tough one, I say.
    By the way, follow the link shared by Karthick and will be easy to answer for anyone.
    Thanks!

  • I am getting "Invalid Identifier" while running the below query

    Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
    select a.*, b.pog_description pog_description, b.start_date,
    row_number() over(partition by b.pog_description order by b.start_date) c_rank
    from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
    where a.sku = c.pog_sku
    and b.pog_id = c.pog_id
    and b.pog_dept = c.pog_dept
    and b.pog_number = c.pog_number
    and b.pog_level = c.pog_level
    and a.sku = 10263477
    and c_rank = 1;

    >
    Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
    select a.*, b.pog_description pog_description, b.start_date,
    row_number() over(partition by b.pog_description order by b.start_date) c_rank
    from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
    where a.sku = c.pog_sku
    and b.pog_id = c.pog_id
    and b.pog_dept = c.pog_dept
    and b.pog_number = c.pog_number
    and b.pog_level = c.pog_level
    and a.sku = 10263477
    and c_rank = 1;
    >
    You can't use 'c_rank' in the where clause because it doesn't exist; you are computing it in the SELECT clause.
    Remove the last condition and wrap your query in another one to select by 'c_rank'.

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Request for tunning the below query

    Hi,
    Can any one help me on the below query while improving the performance,
    SELECT accdet, acceprec, accinvalid, accnetanal, accphy, accvalid,
    actlabcost, actlabhrs, actualcontactdate, actualfinish, actualstart,
    affecteddate, affectedemail, affectedperson, affectedphone,
    alteration, aslaiddwg, assetnum, assetorgid, assetsiteid,
    assumptions, basedet, basereq, bicounty, bidplo, bieasting,
    bihousename, bihouseno, binorthing, bipobox, bipostcode, biposttown,
    bistreet, bisubb as bisupp, boostcomp, boostcompdet, ccemail, cchouseno, ccid,
    ccname, cctel1type, cctel2type, cctelephone1, cctelephone2, cdm,
    changeby, changedate, CLASS, classstructureid, cocontact, cocounty,
    codplo, coeasment, coeasting, cohousename, conorthing, copobox,
    commodity, commoditygroup, coneasereq, consent, consents,
    copostcode, coposttown, costcon, costreet, cosubb, cpi90,
    createworelasset, customerref, custtype, depot, description, durt,
    ecvpressuretier, ecvsize, enduserid, engdifficult, exaoq, existin,
    existsdq, expid, exshq, externalrecid, extralanddetail, failurecode,
    fr1code, fr2code, fuelpovscheme, g17, gbna, glaccount,
    globalticketclass, globalticketid, govconf, govener, govenerdet,
    govhouse, hasactivity, hasld, historyflag, impact, infill,
    infoprovide, inheritstatus, internalpriority, interquote, isglobal,
    isknownerror, isknownerrordate, kioskdet, kioskreq, langcode,
    latecertdate, leadt, lengthpri, lengthpub, loadtype, LOCATION, m25,
    maindesac, mainusage, meterboxty, metercon, meterloc, meterser,
    mininforec, mininforeq, mprnno, newaoq, newpid, newsdq, newshq,
    np14, nrswa, nsgno, oldquotever, oldticketid, orgid, originsgn,
    origrecordclass, origrecordid, origrecorgid, origrecsiteid, owner,
    ownergroup, packagesent, paymethod, payterms, permittowork, physub,
    pressuretier, privateexc, problemcode, propertiesno, propertytype,
    publicexc, purgerel, quotedate, quotetype, quotever, reinforcement,
    reinforcementa, reinforcementb, relatedtoglobal, reportdate,
    reportedby, reportedemail, reportedphone, reportedpriority,
    rowstamp, sc, scj, scoreq, servicerelay, sgnbillcontact,
    sgnblkbyfin, sgncusttobill, sgncusttosite, sgndisreasoth,
    sgneasment, sgnenhance, sgneow, sgneowreq, sgngqmvalid,
    sgninfillcost, sgninfillver, sgninfprojno, sgnisstdchrg,
    sgnloadnoenter, sgnmainsreq, sgnmaxaccdate, sgnnoncont, sgnpipesiz,
    sgnpurord, sgnqdaysremain, sgnqstd, sgnquotdate, sgnquotval,
    sgnreasdis, sgntotalaoq, sgntotalshq, sgnvarreq, sicontact,
    sicounty, sidplo, sieasting, sihousename, sihouseno, sinorthing,
    sipobox, sipostcode, siposttown, sistreet, sisubb, sitecond, sitegt,
    siteid, sitel1, sitel2, siteplpro, sitevisit, solution, sos,
    sosrecdate, SOURCE, status, statusdate, subfinal, supervisor,
    supplytype, surveycarr, surveydef, surveyreas, surveyreq, surveyret,
    surveysent, targetcontactdate, targetfinish, targetstart, TEMPLATE,
    templateid, termtype, thirdpartyeas, thirdpartypipe, ticketid,
    ticketuid, totalaoq, totalpid, totalsdq, totalshq, traffictime,
    typewo, urgency, variat, vendor, customer_enquiry_ref,
    quote_version, costs, mains_infill_charge, mtr_housing_kiosk_charge,
    mtr_housing_kiosk_base_charge, specialist_reinstatement,
    easement_charge, total_quote_ex_vat, vat, total_quote_incl_vat,
    design_charge, reinforcement_charge, reinforcement_cost,
    connection_allowance, workorder.pscdate, workorder.ascdate,
    workorder.fincode, workorder.istask, workorder.status,
    workorder.targstartdate, workorder.targcompdate,
    workorder.schedfinish, workorder.actfinish, workorder.estdur,
    workorder.wonum, workorder.mprn,
    workorder.sihousename AS wositehousename,
    workorder.sihouseno AS wositehouseno,
    workorder.sistreet AS wositestreet,
    workorder.sicounty AS wositecounty,
    workorder.siposttown AS wositeposttown,
    workorder.sipostcode AS wositepostcode, workorder.workorderid
    FROM (maximo.sr
    INNER JOIN
    (maximo.relatedrecord INNER JOIN maximo.workorder
    ON relatedrecord.relatedreckey =
    (CASE
    WHEN workorder.PARENT IS NOT NULL
    THEN workorder.PARENT
    ELSE workorder.wonum
    END
    AND relatedrecord.orgid = workorder.orgid
    AND relatedrecord.siteid = workorder.siteid
    AND relatedrecord.relatedrecclass = 'WORKORDER')
    ON sr.ticketid = relatedrecord.recordkey
    AND sr.orgid = relatedrecord.orgid
    AND sr.siteid = relatedrecord.siteid
    AND relatedrecord.CLASS = 'SR')
    LEFT JOIN
    frozen_quote@gqmfof
    ON sr.ticketid = customer_enquiry_ref
    AND sr.quotever = quote_version
    Regards,
    grace

    Could you please provide more info.
    Refer to the following link.
    When your query takes too long ...
    thanks

  • How to execute the output of the below query automatically

    Hi All,
    I want to execute the output of the below query automatically, instead of manually copying it and execute.
    select 'alter database ['+name+'] set recovery simple' from master.sys.databases where database_id > 4 and state_desc = 'online'
    Please provide me a script to do this.
    ThanK
    Kate

    EXEC sp_MSforeachdb N'ALTER DATABASE [?] SET recovery simple';--- This will set the recovery model for all the system database.The query provided by Vikash16, meets my requirement. Thank you.

  • Need help in the below command excution

    Hi Champs,
    Can any one help with the below command, It is not working.
    Get-CsUser | Where-Object {$_.dialplan -eq "USDAL"} | Grant-CsLocationPolicy -PolicyName "Dallas Location Policy"
    Regards
    Vijendhar

    You could try something like: 
    $userlist = Get-CsUser -ResultSize Unlimited
    foreach ($user in $userlist)
    if ($user.dialplan -eq $Null)
    $pool = (Get-csdialplan | Where-Object {$_.Identity -like ("*" + $user.RegistrarPool)})
    if ($pool.length -ge "1") {write-host ("Pool simple name: " + $pool.simplename + ", Identity: " + $pool.identity)}
    if (($pool.simplename -eq "USDal") -or ($pool.identity -eq "USDal"))
    Write-host "Please Grant location policy to: $user.Displayname"
    # Get-csuser $user.identity | Grant-CsLocationPolicy -PolicyName "Dallas Location Policy"
    $pool = $Null
    Use at your own risk as I haven't had a chance to test, I have commented out the grant so you can test prior to changes.
    Please mark posts as answers/helpful if it answers your question.
    Blog
    Lync Validator - Used to assist in the validation and documentation of Lync Server 2013.

  • How the below query is working

    Hi,
    I am newly joined in the group.
    the emp table has 5 rows as below
    100     ram     10000.00     10
    200     kumar     15000.00     10
    300     william     20000.00     10
    400     ravi     25000.00     10
    500     victor     30000.00     10
    i execute the below query
    select ename,sal from emp_test where case when sal < 10000 then sal + 1000
    when sal < 20000 then sal + 2000
    else sal
    end < 20000
    it gives the below output
    ram     10000.00
    kumar     15000.00
    How the above query is working?
    Please explain. thanks in advance

    If you want it to show the changed salary, it has to be in the select line not the where:
    select ename,
           (case when sal < 10000 then sal + 1000
               when sal < 20000 then sal + 2000
               else sal
            end) sal from emp_test
    where  case when sal < 10000 then sal + 1000
               when sal < 20000 then sal + 2000
               else sal
            end < 20000

  • I need help on the below problem..

    Hi All,
    I need help on the below problem..
    I've 2 Schemas called
         1. MAXIMO and DBLink is GQMFOF
         2. GQMMGR adn DBLink is MAXFOFNC
    Now i would likw to retrive the data from both the schemas,
    i.e some columns from WORKORDER table of maximo schema and some columns from ESTIMATE_HEADER table
    of GQMMGR schema..
    I'm trying to get the data using DB links, but it is giving TABLE/VIEW doesn't exist.
    Please help me on this.
    Regards,
    gr.

    Does your user has the SELECT privelage granted for accessing those tables?

  • Need help in the sql query

    i have a table
    source table :
    create table order(name_a varchar2(100),intid number);
    insert into order values('a',1);
    insert into order values('b',1);
    insert into order values('c',1);
    insert into order values('d',1);
    insert into order values('e',2);
    insert into order values('f',2);
    insert into order values('g',2);
    i need a query , which result in the below output :
    if i look for intid=1 the query should give a,b,c,d
    if i look for intid=2 the query should give f,g
    Thanks

    Hi,
    781649 wrote:
    i have a table
    source table :
    create table order(name_a varchar2(100),intid number);
    insert into order values('a',1);
    insert into order values('b',1);
    insert into order values('c',1);
    insert into order values('d',1);
    insert into order values('e',2);
    insert into order values('f',2);
    insert into order values('g',2);Thanks for posting the CREATE TABLE and INSERT statements; it's very helpful.
    i need a query , which result in the below output :
    if i look for intid=1 the query should give a,b,c,d
    if i look for intid=2 the query should give f,gDid you mean <b>e</b>,f,g ?
    That's called String Aggregation , and how to do it depends on your version of Oracle, and your exact requirements.
    See thie following page for several techniques:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    If you're using Oracle 10 (or higher), and it's important that the name_a's be in order in the output, then you can do this:
    WITH     got_r_num     AS
         SELECT     name_a
         ,     intid
         ,     ROW_NUMBER () OVER ( PARTITION BY  intid
                                   ORDER BY          name_a
                           )         AS r_num
         FROM     order_table                    -- ORDER is not a good table name
         WHERE     intid     IN (1)                    -- Optional
    SELECT     intid
    ,     SUBSTR ( SYS_CONNECT_BY_PATH (name_a, ',')
                , 2
                )     AS name_a_list
    FROM     got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     r_num     = 1
    CONNECT BY     r_num     = PRIOR r_num + 1
         AND     intid     = PRIOR intid
    ;Starting in Oracle 11.2, LISTAGG is better.
    This does not assume that you are getting the output only for a single intid at a time. You can get any number of them in a suingle query. Of course, that number can be 1 if that's what you want.
    Edited by: Frank Kulash on Mar 24, 2011 12:19 PM

  • Reduce the execution time for the below query

    Hi,
    Please help me to reduce the execution time on the following query .. if any tuning is possible.
    I have a table A with the columns :
    ID , ORG_LINEAGE , INCLUDE_IND ( -- the org lineage is a string of ID's. If ID 5 reports to 4 and 4 to 1 .. the lineage for 5 will be stored as the string -1-4-5)
    Below is the query ..
    select ID
    from A a
    where INCLUDE_IND = '1' and
    exists (
    select 1
    from A b
    where b.ID = '5'
    and b.ORG_LINEAGE like '%-'||a.ID||'-%'
    order by ORG_LINEAGE;
    The only constraint on the table A is the primary key on the ID column.
    Following will be the execution plan :
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=406 Card=379 Bytes=2
    653)
    1 0 SORT (ORDER BY) (Cost=27 Card=379 Bytes=2653)
    2 1 FILTER
    3 2 TABLE ACCESS (FULL) OF 'A' (Cost=24 Card
    =379 Bytes=2653)
    4 2 TABLE ACCESS (BY INDEX ROWID) OF 'A' (Co
    st=1 Card=1 Bytes=6)
    5 4 INDEX (RANGE SCAN) OF 'ORG_LINEAGE'
    (NON-UNIQUE)

    I order it by the org_lineage to get the first person. So it is a result problem? The order by doesn't give you the first person, it gives you a sorted result set (of which there may be zero, one, or thousands).
    If you only want one row from that, then you're spending a lot of time tuning the wrong query.
    How do you know which ORG_LINEAGE row you want?
    Maybe it would help if you posted some sample data.

  • How can I replace the cursor in the below query?

    I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
    required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
    DECLARE db_cursor_ava CURSOR
    FOR
    SELECT t.[agent-id],
    t.[start-date],
    t.[end-date],
    t.[monitor-days],
    t.[monitor-start],
    t.[monitor-end],
    t.[timezone-offset]
    FROM @tmpAgentPeriodTimeRange t
    OPEN db_cursor_ava
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DELETE
    FROM @tmpMonitorPeriod
    DELETE
    FROM @tmpFinalResult
    SET @runID = 1
    IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
    BEGIN
    SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
    END
    INSERT INTO @tmpMonitorPeriod
    EXEC core.usp_GetMonitoringPeriod
    @startDate = @stDateTime_ava,
    @endDate = @endDateTime_ava,
    @monitoringDays = @monDays_ava,
    @monitoringStart = @monSt_ava,
    @monitoringEnd = @monEnd_ava
    SELECT @maxID = MAX(tm.id)
    FROM @tmpMonitorPeriod tm
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    END
    CLOSE db_cursor_ava
    DEALLOCATE db_cursor_ava
    mayooran99

    You've been down this path before  - and the response is exactly the same.
    how to replace cursor logic
    And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach.  Who knows
    - but it appears you may have prematurely assumed that the cursor is the problem.

  • Need help in the following query

    Hi ,
    I have the following query to pull out data for a particular timeperiod( campaign)
    select
    da.acct_nr,smas.mrkt_id,smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,
    smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,prev.*
    From cdw.sum_mrkt_acct_sls smas
    join codi.dim_acct da
    on (smas.mrkt_id = da.mrkt_id and smas.acct_key = da.acct_key)
    join codi.dim_acct da1
    on (smas.mrkt_id = da1.mrkt_id and smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in
    select dwnln_acct_key from codi.dim_ldrshp_genlgy
    where mrkt_id = 66 and fld_sls_cmpgn_perd_id = 20100304
    and root_upln_acct_key = (select acct_key from codi.dim_acct where acct_nr = '0032622' and mrkt_id = 66)
    and
    smas.mrkt_id = 66
    and smas.fld_sls_cmpgn_perd_id = 20100304
    and smas.sls_org_key <> -100
    order by 1
    So this query will pull out data for campaign 20100304
    No i want to modify the query to pull out data for 3 such campaigns.
    for a smas.acct_key
    so data will
    smas.acct_key all the data for 1st campaign , all the data for 2nd campaign. all the data for 3rd campaign
    Could you please help in modifying this query.
    Thanks

    How about this ??
    select da.acct_nr,
           smas.mrkt_id,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           prev.*
      From cdw.sum_mrkt_acct_sls smas
      join codi.dim_acct da on (smas.mrkt_id = da.mrkt_id and
                               smas.acct_key = da.acct_key)
      join codi.dim_acct da1 on (smas.mrkt_id = da1.mrkt_id and
                                smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in (select dwnln_acct_key
                               from codi.dim_ldrshp_genlgy
                              where mrkt_id = 66
                                and fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
                                and root_upln_acct_key =
                                    (select acct_key
                                       from codi.dim_acct
                                      where acct_nr = '0032622'
                                        and mrkt_id = 66))
       and smas.mrkt_id = 66
       and smas.fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
       and smas.sls_org_key - 100
    order by 1

Maybe you are looking for

  • Please help. Why aren't my hyperlinks moving over from one document to another?

    Firstly I'm using Adobe InDesign 5.5 I have document A, which has over 50 pages. Then document B, with over 40 pages. All the pages on document B, I want to 'move' over to document A, so document A will now have 90 pages and I'll no longer need docum

  • Web Service proxy deployment and reuse

    Jdev. 11.1.1.4 Hi, In my ADF application I have created a web service proxy with Jdev wizard. I have created a method in order to test it and it works ok. Now, I need to reuse this proxy (the package) in other java applications also in Jdev but worki

  • Remove context menu for the taskbar

    Good afternoon, It is possible to restrict only one program to be executed by the taskbar? The aim is to be able to open all programs by the taskbar by right click, with the exception of one. Cmpts,

  • What is best solution for using a Palm Tungsten 2 on a Windows 7 computer?

    Driven by the end of XP, I purchased an HP Z230 Workstation running Windows 7 Professional.   I'd like to get my Palm Tungsten 2 working, and I've heard several options here on doing that. OPTIONS A.  Use Palm Desktop 6.2 with Bluetooth for hotsync. 

  • Extended access list on Cisco routers

    Can you edit an access list without delete the entire list? In other words, can you remove a sequence entry with the access list? Thanks