Re: Query requirement

Hi Guys,
Need your help. I have to make a Query. The scenario looks like this:
Report has rows: Sales doc no, start date, end date, cancellation date
Report has columns:  Prev period, new bkng, Cancels, Expired, Current yr, Net, plan cost
Req
1) if cancellation date or end date has not yet happened, whichever date is later, then Current yr, Net, plan cost shud be populated
if cancellation date or end date has happened, whichever date is later, then Current yr, Net, plan cost shud not be populated and cancels amount shud be populated
2) if the start date is start of fiscal year i.e  10/1/2007 then, prior year eg 8/4/2006(end date) - sales doc shud be showed also but if there are two or more prior year sales doc with end date before 10/1/2007 then take the prior year sales doc with largest end date.
note:- the 3rd point functionality is only done for start of fiscal yr that is october 10
and Expired, Prev period, shud be populated in prior year sales doc but no value for current yr , no value for plan cost - shud be populated.
3) If cancellation or end date has happend, then only a cancellation flag Y or N should be set
If current sales doc doesnot have cancellation date then flag is set to blank
If cancellation date or end date is not yet happened then flag is also set to blank
Set flag to Y if an Object 0Reason has value AR or else if has no value then set to N
4) If selection month eg 5/2007 and end dat eis 2/2007 then Net value shud show up in expired till end of fiscal year and a Truly expired should be set Y or N
if there is no future period for slaes doc in the table /cube then set it to Y
if there is future period for slaes doc in the table /cube then set it to N
5) A truly new booking Y or N flag shud be set if there is no prior sales doc i.e truly a new booking. The start date falls in the current fiscal year
Thanks
Rob

Well, for example on this one:
"if cancellation date or end date has not yet happened, whichever date is later, then Current yr, Net, plan cost shud be populated
if cancellation date or end date has happened, whichever date is later, then Current yr, Net, plan cost shud not be populated and cancels amount shud be populated"
You need to create formula variables of type replacement path for the dates (there are several posts that talk about this) and then compare it with the formula variable for the system date (this is provided by SAP). The result would be a True (1) or False(0) and appropriately you can create a formula to multiply the result of this decision by the KF you want to display or not display in the said condition.
Hope this helps...

Similar Messages

  • Adhoc Query Requirement with Multiple Data Source

    Hi All,
    I have a Adhoc Query Requirement with Multiple Data Source. Is there any way to achive it. Other than Resultant set and bring into Model.
    Thanks
    SS

    You can compare stuff in the EL, but I don't think this is what you need.
    You can just use Java code in the backing bean class for all the business logic. You can use DAO classes for database access logic. Finally for displaying you can use the JSF tags such as h:outputText.

  • Reg: Complex query requirement-

    Hi Experts,
    I am having a query requirement which seems to be kind-of complex. Below I try to provide the pseudo-code:
    -->>-- CASE (1)
    IF EXISTS (
    select new_amt
    from table_stp stp
    where stp.chng_dt = (
      select MAX(a.chng_dt)
      from table_stp stp
      where
       stp.chng_dt <= due_dt
       and stp.new_amt IS NOT NULL
    -->>-- CASE (2)
    ELSE IF EXISTS(
    select old_amt
    from table_stp stp
    where stp.chng_dt = (
      select MIN(a.chng_dt)
      from table_stp stp
      where
       stp.chng_dt <= due_dt
       and stp.old_amt IS NOT NULL
    ELSE 0
    Some sample scenario -
    LNO CHNG_DT  NEW_AMT OLD_AMT
    1 12-01-2013 100  null
    1 13-01-2013 200  666
    1 14-01-2013 null 777
    2 17-01-2013 null 555
    2 18-01-2013 null 888
    2 19-01-2013 null 999
    Output should be:
    1     13-01-2013     200      666 -->>-- case 1
    2     17-01-2013     null     555 -->>-- case 2
    Please let me know if you need any other clarification.
    Could you please help me with this?
    Help much appreciated.
    Thanks,
    Ranit
    (on Oracle 11.2.0.3.0)

    Hi Frank,
    I guessed that my initial post will need some additional inputs. Let me try to describe my requirement more clearly:
    Sample data --
    with table_stp(LNO,CHNG_DT,NEW_AMT,OLD_AMT,col1,col2,col3,col4) as(
        select 1, TO_DATE('12-01-2013','dd-mm-yyyy'), 100, NULL, 11,12,13,14 from dual UNION ALL
        select 1, TO_DATE('13-01-2013','dd-mm-yyyy'), 200, 666, 21,22,23,24 from dual UNION ALL
        select 1, TO_DATE('14-01-2013','dd-mm-yyyy'), NULL, 777, 31,32,33,34 from dual UNION ALL
        select 2, TO_DATE('17-01-2013','dd-mm-yyyy'), NULL, 555, 41,42,43,44 from dual UNION ALL
        select 2, TO_DATE('18-01-2013','dd-mm-yyyy'), NULL, 888, 51,52,53,54 from dual UNION ALL
        select 2, TO_DATE('19-01-2013','dd-mm-yyyy'), NULL, 999, 61,62,63,64 from dual    
    select *
    from table_stp;
    My expected output --
    1     13-01-2013     200      666     21     22     23     24 -->>-- case 1
    2     17-01-2013     null     555     41     42     43     44 -->>-- case 2
    Logic --
    (1) First, we need to check if Case - 1 satisfies or not.
    (1.1) If Yes, do some task.
    (1.2) If Not, check if Case - 2 satisfies or not.
         (1.2.1) If Yes, do some task.
         (1.2.2) If Not, set value = 0
    Case - 1)
    First, all records with "NEW_AMT" as null are eliminated and we need to fetch the value "NEW_AMT" with maximum "CHNG_DT".
    So, first output record is scenario Case - 1.
    Case - 2)
    If all values for a LNO is null for column "NEW_AMT", we need to look into column "OLD_AMT" for the value with minimum "CHNG_DT"
    Second output record lies here, because - all record values for column "NEW_AMT" is null, we need to consider column "OLD_AMT" for values,
    Still, if all values in OLD_AMT is null, set = 0
    Hope this gives a better understanding, else please let me know.

  • Query Requirment

    Hi
    I had a strange Query Requirement....and wondering is there any way to achieve this with out using Cell editor
    In columns i had Previous,Current and Next Year in months (3*12=36) (Restrictions on Current Cal year Variable and Month)
    In Rows Formula...but the formula should be Populated with KF X for all the months Less than current month and Populated by Y for all months Greater than Current Month
    Any options

    So you want if curent is Feb:
           lastJan   curJan nextJan lastFeb curFeb.....
    F:    X            X          Y         X           Y
    define formula variable FV1 replaced by key 0calyear and FV2 replaced by key 0calmonth
    F= (FV1<curent year)X+(FV1=curent year)(FV2>=Curent month)Y+(FV1=curent year)(FV2<Curent month)X+(FV1>current year)Y
    see note 1385580 about formula var

  • Can anyone solve this query requirement

    Would like to know if anyone solved this situation in the query before. If yes, or If you have any ideas, could you please share it with me.
    Below is the scenario.
    Cube data: We have a number of 'FACILIIES'. 'Surveys' are conducted for each facility once in every six to 18 months. No fixed time intervals though. And surveys are numbered sequencially, always in the increasing order with respect to time. each survey has a 'survey date'. and a keyfigure 'Count'.                                                  
    DATA IN THE CUBE AS OF 4/30/2005               
    FACILITY...SURVEYID...SURVEYDATE...COUNTKEYFIGURE     
    525...         121...  1/6/2004...         6     
    624...         132...  2/20/2004...    7     
    525...         138...  10/1/2004...    5     
    624...         140...  9/15/2004...    4     
    525...         157...  3/10/2005...    8     
    624...         245...  4/15/2005...    6     
    If the query is run for the above data, is shouls be displayed like this.               
    REPORT AS OF 04/30/2005                    
    FACILITY...LATESTSURVEY...LATESTCOUNT...PREVIOUSSURVEY PRECOUNT
    525... 157... 8... 138... 5
    624... 245... 6... 140... 4
    Once the data is updated further, this is the data in the Cube as of 10/30/2005
    DATA IN THE CUBE AS OF 10/30/2005          
    FACILITY...SURVEYID...SURVEYDATE...COUNTKEYFIGURE     
    525...          121...     1/6/2004...     6     
    624...          132...     2/20/2004...     7     
    525...          138...     10/1/2004...     5     
    624...          140...     9/15/2004...     4     
    525...          157...     3/10/2005...     8     
    624...          245...     4/15/2005...     6     
    525...       290...     8/20/2005...     9     
    624...          312...     10/15/2005...     4     
    REPORT AS OF 04/30/2005                         
    FACILITY LATESTSUREY LATESTCOUNT PREVIOUSSURVEY PRECOUNT
    525...          290...     9...          157...     8     
    624...          312...     4...          245...     6     
    Dynamically, the latest survey and previous survey has to be determined. Any ideas on how to solve... We alrady thought of making changes to the Survey Master data. Any thing that can be done in the query itself?
    thanks
    Gova
    (I could not improve the display format, so I used '...' to separate the fields. may be SDN should look into improving the display format)

    Hi Gova..
    We too had a similar requirement..to get the previous records..
    We had to end up having to populate the Previous record in a seperate field on the same line..
    I think you are on the right path to modify the master data and have the previous survey and previous count populated on every line..
    Good Luck
    Ashish..

  • Query required

    Hi
    I have a table and data like like
    Desc emp_entry_error;
    Emp_NO Number;
    Emp_FName Varchar2(16);
    Emp_Lname Varchar2(16);
    Emp_err_Sal Varchar2(15);
    Emp_DOJ Date;
    EMP_No EMP_Fname Emp_Lname Emp_Err_sal Emp_DOJ
    100000 Ganesh Arju 10000- (Left Align) 02-12-1950
    100001 Dilip- Mathew 20000 (Left Align) 09-05-1965
    100002 Sunil Shetty - 10000(Left Align) 02-12-1950
    100003 Garry- George 29000 (right Align) 09-05-1966
    100003 Gundu Rao 25000-- (right Align) 09-05-1966
    This table will be inserted when user make any mistake while inserting data. Here in the given data set EMP_ERR_SAL is inserted with worng values. [e.,g] -(Minus) sign after Digit(10000-) and Space after Minus Sign (- 10000) and two Minus(25000--).
    Requirment is like Do the sum on EMP_ERR_SAL: SUm only if it is a valid Number Like(20000,29000) Skip the values which are not the numbers Like(10000-,- 10000,25000--).
    OVerall when i Do select Query on EMP_ERR_SAL Output should be like
    SUM(EMP_ERR_SAL)
    49000 ------------------------> Consider only records 2 and 4th row. Omit the records 1,3,5
    Please Provide me a query to find this. I have done with regular expr already but is not working. Please share some other ideas or SQL query for above requirement.
    Early Response is very much appreciated.
    Thanks,
    Santhosh.S

    Hi, Santhosh,
    Good start!
    Let's forget about SUM for now: if we can figure out an expression that returns s if string s is a well-formed number, and returns NULL otherwise, then you'll know how to get the SUM.
    So your query now is essentially:
    SELECT     emp_sal
    ,     REGEXP_SUBSTR     ( emp_sal
                   , '[[:digit:]]+'     -- 1 or more digits
                   )     AS num_txt
    FROM     emp;and it produces these results:
    EMP_SAL         NUM_TXT
    10000-          10000
    20000           20000
    - 10000         10000
    29000           29000
    25000--         25000What's wrong with with the query above? It's returning the digit part of the string regardless of whether of not there are other characters, either before or after the digits, that make the string an invalid number. That's because patterns in REGEXP functions are, by default, not anchored. If we want a pattern that appears at the beginning or end of a string (or both, which is to say it is the entire string) we have to explicitly say so, like this:
    SELECT     emp_sal
    ,     REGEXP_SUBSTR     ( emp_sal
                   ,  '^'               -- Start of string
                   || '[[:digit:]]+'     -- 1 or more digits
                   || '$'               -- End of string
                   )     AS num_txt
    FROM     emp;Results:
    EMP_SAL         NUM_TXT
    10000-
    20000           20000
    - 10000
    29000           29000
    25000--Is that what you need? If not, what else has to be done?
    Do you need to allow an optional plus or minus sign at the beginning? If so, then test for zero or one occurrences of '(\+|-)' immediately after the Start-of-string and immediately before the digits.

  • Query required to get data

    hi
    i need to a query to get the data as per given structure below.
    tha data should be based on stock code and dates.
    for example : stock_code = 01 and
    from date 01/01/08
    to date 31/01/08
    Date particulars reciepts issued returns closing bal
    01/01/08 opening balance 0
    01/01/08 recieved stock : no 1 18 18
    02/01/08 issued stock : no 5 5 13
    03/01/08 return stock : no 50 3 16
    and so on
    here is the tables i m using
    SQL> desc bal_sheet (balance sheet holds the opening and closing record)
    Name Null? Type
    BDATE DATE
    ACC_CODE VARCHAR2(20)
    OPENBAL NUMBER(20,4)
    CLOSEBAL NUMBER(20,4)
    SQL> desc stock_reg
    Name Null? Type
    STOCKCODE NOT NULL VARCHAR2(20)
    ITEM_CODE VARCHAR2(10)
    DESCR NOT NULL VARCHAR2(50)
    COMCODE VARCHAR2(6)
    COMPANY NOT NULL VARCHAR2(200)
    SHORT_NAME VARCHAR2(10)
    PACK VARCHAR2(10)
    PRICE NUMBER(10,4)
    TOTAL_STOCK NUMBER
    SQL> DESC PURCHASE_HEADER
    Name Null? Type
    P_ID NOT NULL VARCHAR2(10)
    ACC_CODE VARCHAR2(10)
    P_DATE DATE
    REMARK VARCHAR2(500)
    INVOICE_DATE DATE
    NTOTAL NUMBER(12,4)
    SQL> DESC PURCHASE_DETAIL
    Name Null? Type
    STOCKCODE VARCHAR2(20)
    P_ID VARCHAR2(10)
    QTY NUMBER
    BONUS NUMBER
    PRICE NUMBER(15,4)
    EXPIRE_DATE DATE
    DAMAGE NUMBER
    AMOUNT NUMBER(15,4)
    SQL> DESC SALES_HEADER
    Name Null? Type
    S_ID NOT NULL VARCHAR2(8)
    ACC_CODE VARCHAR2(10)
    SALES_MANID VARCHAR2(20)
    S_DATE DATE
    REMARKS VARCHAR2(500)
    NTOTAL NUMBER(12,4)
    SQL> DESC SALES_DETAIL
    Name Null? Type
    S_ID NOT NULL VARCHAR2(8)
    STOCKCODE NOT NULL VARCHAR2(20)
    QTY NUMBER
    BONUS NUMBER
    BATCH_NO NOT NULL VARCHAR2(10)
    EXPIRY_DATE DATE
    AMOUNT NUMBER(15,4)
    SQL> DESC SALES_HEADER
    Name Null? Type
    SR_ID NOT NULL VARCHAR2(8)
    ACC_CODE VARCHAR2(10)
    SALES_MANID VARCHAR2(20)
    S_DATE DATE
    REMARKS VARCHAR2(500)
    NTOTAL NUMBER(12,4)
    SQL> DESC SALES_DETAILR
    Name Null? Type
    SR_ID NOT NULL VARCHAR2(8)
    STOCKCODE NOT NULL VARCHAR2(20)
    QTY NUMBER
    BONUS NUMBER
    BATCH_NO NOT NULL VARCHAR2(10)
    EXPIRY_DATE DATE
    AMOUNT NUMBER(15,4)
    hope the information would be enough to get understand the problem

    Query required to get data Agreed ! Even on your side it is required.
    Well, please, understand we are not here to do your job. So, make effort on your side, show us what you have already done/tried, and post here your results.
    And also, use the tags &#091;pre&#093; and &#091;/pre&#093; around your code against the forum side to keep your post readable.
    Help us to help you,
    Nicolas.

  • Query Required for FMS

    Dear Expert
               I want the Query for to convert Value in to words,the value is  the document total value.

    HI,
    Try This It may help you
    ->> Create 1 UDF in Header on Requrie Documents (ex. Marketing Documents).
    ->> Create 3 Function in MSSQL Server Management.
    ->> Create 1 FMS in Query Generator and save as Query Manager then Assign to UDF for Amount in Words.
    for example:
    Create UDF in Header on Marketing Documents.
    ->> Choose Tools on Top menu.
    ->> User - Defined Fields. -> User Manage Fields.
    ->> Open the User Manage Fields Widnow.
    ->> Marketing Documents. -> Title.
    ->> Select Title and Click Add button in Bottom on User Manage Fields Window.
    ->> Create Amount in Words UDF(Code, Discription and Type - Character) and Add the UDF.
    Create Function in MSSQL Server Management.
    Check this Link, (have 3 Functions in Link).
    http://techcreeze.blogspot.com/2008/11/convert-amount-into-words-according-to_15.html
    1st Funciton - to Convert one Digit Number to words
    2nd Funciton - to convert 2 digit number to words.
    3rd Funciton - to convert amt in numbers to words.
    ->> Open the MSSQL Server Management Window.
    ->> Choose your Company database and Create NEW Query.
    ->> Create 3 Function Queries one by one.
    ->> Create 3 NEW Query Tab and 1st one put the 1st Function then Run the Function. and
    2nd New Query tab put the 2nd Function then Run the Function.
    3rd New Query tab put the 3rd Function then Run the Function.
    Create FMS in Query Generator and Save as Query Manager.
    ->> Adminstration.
    ->> Reports. -> Query Generator.
    ->> Open the Query Generator and put the below FMS query.
    for example : Purchase Order Doc. Toal(in wrods).
    declare @Doc_total numeric (19,6)
    set @Doc_total=$http://OPOR.DocTotal
    select dbo.fNumToWords (@Doc_total)
    ->> Assign the FMS in UDF on Purchase Order.
    ->> Auto Refresh of Document Total.
    Ex.
    1. Goto the UDF and Clcik Shift+Alt+F2.
    2. Select the SEARCH BY SAVED QUERY.
    3. Assign the FMS Query.
    4. Select the AUTO REFRESH WHEN FIELD CHENGES.
    5. Select Document Total.
    6. Check the Display Saved Values
    I am including here, source code of functions required for converting Number into words according to Indian or Nepali Numbering style. In Indian or Nepali Numbering style, 100000 is 1 Lakh and 100 Lakhs or 10000000 is 1 Crore. This makes the numbering style different from English and International Numbering Style.
    1. Function to Convert one Digit Number to words.
    CREATE    Function dbo.fConvertDigit(@decNumber decimal)
    returns varchar(6)
    as
    Begin
    declare
    @strWords varchar(6)
    Select @strWords = Case @decNumber
         When '1' then 'One'
         When '2' then 'Two'
         When '3' then 'Three'
         When '4' then 'Four'
         When '5' then 'Five'
         When '6' then 'Six'
         When '7' then 'Seven'
         When '8' then 'Eight'
         When '9' then 'Nine'
         Else ''
    end
    return @strWords
    end
    2. Function to convert 2 digit number to words.
    CREATE    Function dbo.fConvertTens(@decNumber varchar(2))
    returns varchar(30)
    as
    Begin
    declare @strWords varchar(30)
    --Is value between 10 and 19?
    If Left(@decNumber, 1) = 1
    begin
    Select @strWords = Case @decNumber
         When '10' then 'Ten'
         When '11' then 'Eleven'
         When '12' then 'Twelve'
         When '13' then 'Thirteen'
         When '14' then 'Fourteen'
         When '15' then 'Fifteen'
         When '16' then 'Sixteen'
         When '17' then 'Seventeen'
         When '18' then 'Eighteen'
         When '19' then 'Nineteen'
    end
    end
    else  -- otherwise it's between 20 and 99.
    begin
    Select @strWords = Case Left(@decNumber, 1)
         When '0' then '' 
         When '2' then 'Twenty '
         When '3' then 'Thirty '
         When '4' then 'Forty '
         When '5' then 'Fifty '
         When '6' then 'Sixty '
         When '7' then 'Seventy '
         When '8' then 'Eighty '
         When '9' then 'Ninety '
    end
    Select @strWords = @strWords + dbo.fConvertDigit(Right(@decNumber, 1))
    end
    --Convert ones place digit.
    return @strWords
    end
    3. Function to convert amt in numbers to words. (Built with the help of above 2 functions)
    CREATE function dbo.fNumToWords (@decNumber decimal(12, 2))
    returns varchar(300)
    As
    Begin
    Declare
    @strNumber varchar(100),
    @strRupees varchar(200),
    @strPaise varchar(100),
    @strWords varchar(300),
    @intIndex integer,
    @intAndFlag integer
    Select @strNumber = Cast(@decNumber as varchar(100))
    Select @intIndex = CharIndex('.', @strNumber)
    if(@decNumber>99999999.99)
    BEGIN
    RETURN ''
    END
    If @intIndex > 0
    begin
    Select @strPaise = dbo.fConvertTens(Right(@strNumber, Len(@strNumber) - @intIndex))
    Select @strNumber = SubString(@strNumber, 1, Len(@strNumber) - 3)
    If Len(@strPaise) > 0 Select @strPaise = @strPaise + ' paise'
    end
    Select @strRupees = ''
    Select @intIndex=len(@strNumber)
    Select @intAndFlag=2
    while(@intIndex>0)
    begin
    if(@intIndex=8)
    begin
      Select @strRupees=@strRupees+dbo.fConvertDigit(left(@decNumber,1))+' Crore '
      Select @strNumber=substring(@strNumber,2,len(@strNumber))
      Select @intIndex=@intIndex-1
    end
    else if(@intIndex=7)
    begin
      if(substring(@strNumber,1,1)='0')
      begin
       if substring(@strNumber,2,1)<>'0'
       begin
        if (@strRupees<>NULL and substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0' and @intAndFlag=2 and @strPaise=NULL)
        begin
         Select @strRupees=@strRupees+' and ' +dbo.fConvertDigit(substring(@strNumber,2,1))+' Lakh '
         Select @intAndFlag=1
        end
        else
        begin
         Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,2,1))+' Lakh '
        end
        Select @strNumber=substring(@strNumber,3,len(@strNumber))
        Select @intIndex=@intIndex-2
       end
       else
       begin
        Select @strNumber=substring(@strNumber,3,len(@strNumber))
        Select @intIndex=@intIndex-2
       end
      end
      else
      begin
       if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0'  and @intAndFlag=2 and @strPaise='')
       begin  
        Select @strRupees=@strRupees+' and ' + dbo.fConvertTens(substring(@strNumber,1,2))+' Lakhs '
        Select @intAndFlag=1
       end
       else
       begin
        Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))+' Lakhs '
       end
       Select @strNumber=substring(@strNumber,3,len(@strNumber))
       Select @intIndex=@intIndex-2
      end
    end
    else if(@intIndex=6)
      begin
       if(substring(@strNumber,2,1)<>'0' or substring(@strNumber,3,1)<>'0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and @intAndFlag=2 and @strPaise='')
       begin
        if len(@strRupees) <= 0
        begin
         if convert(int,substring(@strNumber,1,1)) = 1
         begin
          Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
          Select @intAndFlag=2
         end
         else
         begin
          Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
          Select @intAndFlag=2
         end
        end
        else
        begin
         if convert(int,substring(@strNumber,1,1)) = 1
         begin
          Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
          Select @intAndFlag=1
         end
         else
         begin
          Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
          Select @intAndFlag=1
         end
        end
       end
       else
       begin
        if convert(int,substring(@strNumber,1,1)) = 1
        begin
         Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
        end
        else
        begin
         Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
        end
       end
       Select @strNumber=substring(@strNumber,2,len(@strNumber))
       Select @intIndex=@intIndex-1
      end
    else if(@intIndex=5)
      begin
       if(substring(@strNumber,1,1)='0')
       begin
        if substring(@strNumber,2,1)<>'0'
        begin
         if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
         begin
          Select @strRupees=@strRupees+' and ' +dbo.fConvertDigit(substring(@strNumber,2,1))+' Thousand '
          Select @intAndFlag=1
         end
         else
         begin
          Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,2,1))+' Thousand '
         end
         Select @strNumber=substring(@strNumber,3,len(@strNumber))
         Select @intIndex=@intIndex-2
        end
        else
        begin
         Select @strNumber=substring(@strNumber,3,len(@strNumber))
         Select @intIndex=@intIndex-2
        end
       end
       else
       begin
        if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
        begin
         Select @strRupees=@strRupees+' and '+dbo.fConvertTens(substring(@strNumber,1,2))+' Thousand '
         Select @intAndFlag=1
        end
        else
        begin
         Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))+' Thousand '
        end
        Select @strNumber=substring(@strNumber,3,len(@strNumber))
        Select @intIndex=@intIndex-2
       end
      end
    else if(@intIndex=4)
      begin
       if ( (substring(@strNumber,3,1)<>'0' or substring(@strNumber,4,1)<>'0') and substring(@strNumber,2,1)='0' and  @intAndFlag=2 and @strPaise='')
       begin
        Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Thousand '
        Select @intAndFlag=1
       end
       else
       begin
       Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Thousand '
       end
       Select @strNumber=substring(@strNumber,2,len(@strNumber))
       Select @intIndex=@intIndex-1
      end
    else if(@intIndex=3)
      begin
       if  substring(@strNumber,1,1)<>'0'
       begin
        Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Hundred '
        Select @strNumber=substring(@strNumber,2,len(@strNumber))
        if( (substring(@strNumber,1,1)<>'0' or  substring(@strNumber,2,1)<>'0') and @intAndFlag=2 )
        begin
         Select @strRupees=@strRupees+' and '
         Select @intAndFlag=1
        end
        Select @intIndex=@intIndex-1
       end
       else
       begin
        Select @strNumber=substring(@strNumber,2,len(@strNumber))
        Select @intIndex=@intIndex-1
       end
      end
    else if(@intIndex=2)
      begin
       if substring(@strNumber,1,1)<>'0'
       begin
        Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))
        Select @intIndex=@intIndex-2
       end
       else
       begin
        Select @intIndex=@intIndex-1
       end
      end
    else if(@intIndex=1)
      begin
       if(@strNumber<>'0')
       begin
        Select @strRupees=@strRupees+dbo.fConvertDigit(@strNumber)
       end
       Select @intIndex=@intIndex-1
      end
    continue
    end
    if len(@strRupees)>0 Select @strRupees=@strRupees+ ' rupees '
    IF(len(@strPaise)<>0)
    BEGIN
    if len(@strRupees)>0 Select @strRupees=@strRupees + ' and '
    END
    Select @strWords = IsNull(@strRupees, '') + IsNull(@strPaise, '')
    select @strWords = @strWords + ' only'
    Return @strWords
    End
    Regards
    Balaji Sampath

  • Query required for JE posted with the customer

    Dear Experts,
                   Following is the scenario - Accountant passes Journal Entries once in a while with regard to customers also, i would require a alert for the scenario.
                    Whenever the user posts a JE with regard to a customer alert has to generate to the manager else a query report is required would do.
    Saravanan

    Hi,
    You can use the below as an alert for Manual Journal Entries that has been created the last 2 days with posting to Business Partner account.
    SELECT t0.transid, t0.shortname
    FROM JDT1 T0 INNER JOIN OJDT T1 ON T0.TransId = T1.TransId
    WHERE shortname <> account and  T1.createdate > getdate()-2 and t0.transtype = 30
    If you want to have a different date range just change the '-2' to the amount of days you want, if you only want entries created today, just remore it. If you prefer it to be by posting date rather than by creaation (system) date, just change createdate to refdate.
    Hope it helps,
    Jesper

  • Query required for below situation.

    Hi All,
    I have two table
    T1 --> deal_site_id, subsection_id
    T2 --> deal_site_id, subsection_id, catalog_id
    requirement is first I need to check all the subsection_id in table T1 depending upon one deal_site_id.
    Then what ever subsection_id I get from table T1 I need to check if those are available in table T2. If they are available then do nothing but if they are not available in table T2 then delete the row from table T1.
    I've tried to write the query like below but stuck with exception.
    DELETE FROM (SELECT * FROM T1 lid inner join T2 ld
    ON LID.DEAL_SITE_ID = LD.DEAL_SITE_ID
    WHERE lid.deal_site_id = 3070
    AND LD.SUBSECTION_ID NOT IN (SELECT DISTINCT liod.subsection_id from T1 liod where liod.deal_site_id = 3070 )
    this is giving me an exception like ORA-01752: cannot delete from view without exactly one key-preserved table
    Please help me to write this query. Thanks in advance.
    Regards,
    Subhadeep
    Edited by: sumajumd on Feb 2, 2012 3:08 AM

    Hi, Subhadeep,
    That sounds like:
    DELETE FROM     t1
    WHERE     deal_site_id     = 3070     -- or whatever
    AND     subsection_id   NOT IN (
                          SELECT  subsection_id
                          FROM    t2
                          WHERE   deal_site_id     = t1.deal_site_id
                          AND       subsection_id     IS NOT NULL     -- If necessary
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as DELETE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.

  • Query required for rule

    Below is the condition for which a query is to be written.
    as of now this the query i have written. am getting the orderids which satisfy this rule but the output should include all those orderids which already satisfy the rule.(i.e the current o/p contains those orderids which share a common circuitid and have same start and end dates. the output required should include this as well as those orderids tat do not share circuitids.
    or
    the o/p should contain those orderids which do not fall into any of these categories)
    The Rule:
    For the Entity Circuit Orders if the Circuit Id is same for two different order IDs then the Order Start Date for the Order Id having Order Status as Installed should be same as the Order End Date for the Order Id having Order Status as Retired.
    Tthe query:
    select order_id from managed_element1 where order_status = 'I' and order_start_date in
    (select order_end_date from managed_element1 where circuit_id in
    (SELECT circuit_id FROM managed_element1 where order_status='R' GROUP BY circuit_id))

    The data is as below
    Order_id circuit_id start_date end_date order_status
    ORDER_67 BORDER_2 03/05/06 05/09/06 R
    ORDER_7 BORDER_6 10/26/06 I
    ORDER_11 BORDER_7 12/05/06 12/06/07 I
    ORDER_1 BORDER_2 05/09/06 05/19/06 R
    ORDER_2 BORDER_2 05/19/06 I
    ORDER_3 BORDER_3 04/03/06 05/20/06 R
    ORDER_4 BORDER_3 05/20/06 I
    ORDER_5 BORDER_4 02/05/06 05/06/06 R
    ORDER_6 BORDER_4 05/05/06 I
    ORDER_7 BORDER_5 10/22/02 02/23/03 R
    ORDER_8 BORDER_5 02/23/03 I
    ORDER_9 BORDER_6 03/12/06 09/26/06 R
    ORDER_10 BORDER_6 09/26/0610/26/06 R

  • Hierarchial Query Requirement

    Hi I have two tables, emp_tab which contains only employee information as below,
    emp_tab
    empno|empname|emptype
    10|SK|EMP
    20|KS|MGR
    30|NAR|ORG
    and another table emp_tab_relation
    emp_tab_relation
    relt_id|emp_id|prnt_relt_id
    1|20|null
    2|10|1
    3|30|1
    i.e, emp_id prnt is it's relation id
    in this case 20 is the manager and his relation id is 1 and so that will be filled in the place of prnt_relt_id,
    now my requirement is I want a query output as below,
    EMPNAME|MGRNAME
    KS|NULL
    SK|KS
    NAR|KS
    Thanks,

    with emp_tab as (
    select 10 empno,'SK' empname,'EMP' emptype from dual union all
    select 20,'KS','MGR' from dual union all
    select 30,'NAR','ORG' from dual
    emp_tab_relation as (
    select 1 relt_id,20 emp_id,null prnt_relt_id from dual union all
    select 2,10,1 from dual union all
    select 3,30,1 from dual
    --test data
    SELECT empname,
      prior empname
       FROM emp_tab p
    JOIN emp_tab_relation r
         ON r.emp_id           = p.empno
      CONNECT BY prior relt_id = prnt_relt_id
      START WITH prnt_relt_id IS NULLRavi Kumar

  • How to query requirements of an sccm 2012 application

    Dear all
    I have some problem to create an OSLanguage or Device_OSLanguage Requirement using powershell script
    it seems that the value passed to the script is not assume by sccm because the record is not availble on the console
    i tryed with 1033 , en-us and so on with no good result
    (the script is running with OS, Space Disk...)
    so i would like to query the requirement values attached to the existing applications to check it and to retry to use my script with correct i hope values.
    cou'ld you help me to resolve this locked problem of my project.
    Many thanks
    François

    Hi
    The trick is to create a CustomCollection of ConstantValue, add each ConstantValue to this CustomCollection then add this CustomCollection to the Expression by using the Int64Array DataType.
    I did it like this in VB .Net and I'm sure you can do the same in PowerShell:
    Dim aobjOperand As CustomCollection(Of ExpressionBase) = New CustomCollection(Of ExpressionBase)
                Dim objOperand As ExpressionBase = New GlobalSettingReference("GLOBAL", "OSLanguage", DataType.Int64Array, "OSLanguage_Setting_LogicalName", ConfigurationItemSettingSourceType.CIM)
                aobjOperand.Add(objOperand)
    Dim aobjLangues As CustomCollection(Of ConstantValue) = New CustomCollection(Of ConstantValue)
    aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-BE").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-CA").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-FR").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-LU").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-MC").LCID.ToString, DataType.Int64))
                        aobjLangues.Add(New ConstantValue(CultureInfo.GetCultureInfo("fr-CH").LCID.ToString, DataType.Int64))
    objOperand = New ConstantValueList(aobjLangues, DataType.Int64Array)
                aobjOperand.Add(objOperand)
    Dim objExpression As Expression = New Expression(ExpressionOperator.OneOf, aobjOperand)
                objRule = New Rule("Rule_" + Guid.NewGuid().ToString("D"),
                                   NoncomplianceSeverity.None,
                                   New Annotation("Langue du système d'exploitation", Nothing, Nothing, Nothing),
                                   objExpression)

  • PlSql query required

    Hello All,
    I have one requirement like below. I've written a StoredProcedure which has i/p parameter as segment_id
    I have two tables T1 and T2
    T1--> line_id,ssection_id,cat_id
    T2--> parent_id,child_id, segment1,segment2,segment3
    parent_id is equivalent to ssection_id and child_id is equivalent to cat_id. I've made a inner join with thise condition.
    Now, what I need to achieve is, depending upon the segment_id i/p parameter i need to check teh data of table T2. for example say, segment_id is segment1 then i have to check the data in segment1 column and if it is N then I should fetch the line_id from table T1.
    SELECT lines.line_id
    BULK COLLECT INTO line_ids
    FROM T1 lines inner join T2 iv
    ON LINES.SSECTION_ID = iv.Parent_id
    AND lines.cat_id = iv.child_id
    WHERE
    Here I need to write the condition that I've explained above. Please forgive me if it is a lame question to ask as I'm very much new to Oracle world. Please let me know if you need any further information. Thanks in advance.
    Regards,
    Subhadeep

    I figured out the query, Thanks a lot for your help.
    AND 'N' = CASE i/pparameter segment
    WHEN 'segment1' THEN
    iv.segment1
    WHEN 'segment2' THEN
    iv.segment2
    WHEN 'segment3' THEN
    iv.segment3
    END ;
    the whole query looks like this.
    SELECT lines.line_id
    BULK COLLECT INTO line_ids
    FROM T1 lines , T2 iv
    WHERE lines.deal_site_id = p_deal_site_id -- i/p parameter
    AND LINES.SSECTION_ID = iv.Parent_id
    AND lines.cat_id = iv.child_id
    AND 'N' = CASE p_segment_id -- segment i/p parameter
    WHEN 'segment1' THEN
    iv.segment1
    WHEN 'segment2' THEN
    iv.segment2
    WHEN 'segment3' THEN
    iv.segment3
    END ;
    Hope it helps some one who is facing similar problem.
    Regards,
    Subhadeep

  • BEx Query requirement

    Hi
    I have a defined query with Material in row and with three keyfigures price (current year), price (current year -1) and price (current year - 3) in column.
    Current year is input variable of query i.e. 2011. It works fine.
    Now my requirement is to define a new cal. key figure which should show the least (minimum) of all above three keyfigures. Moreover I have identify the year
    of least (minimum) price to calculate another cal. key figure/restriced key figure.
    Thanks

    Hi
    Like arvind mentioned you can calculate min by boolean exp
    like ur 3 kf are KF1,KF2,KF3 for 3 years. So now you can write
    KF1(KF1<KF2)(KF1<KF3)*(KF1>0)..KF1>0 to exclude blank values
    Similarly for 2nd problem you will have to create that 2nd restricted/calculated KF for all 3 years say KF2_YEAR1,KF2_YERA2,KF2_YEAR3. Now at the same time cretae 3 more CKF like CKF1 = (KF1<KF2)*(KF1<KF3).
    CKF1 tells KF1 is minimum. Now KF2_YEAR1*CKF1 will be populated if KF1 will be minimum. So you requirement will be full filled from followin final formula
    KF2_YEAR1CKF1  + KF2_YEAR2CKF2  + KF2_YEAR3*CKF3
    Hope this is fine.
    Thanks
    Dheeraj

  • Why this query required 2 extra columns in GROUP BY

    Hi All,
    This is my query:
    SELECT "parent_level_id",
           "parent_level_name"
           "parent_level_id",                    
           "child_level_id",
           "child_level_name",
           "scenario_id",
           "scenario_name",
           "exported",
           "regress_cob",
           "scn_status_id",
           "tgt_scenario_name",
           "load_status_id",
           "load_count",
           "PRESENT_VALUE",
           "DELTA",
           "GAMMA",
           "VEGA",
           "PNL",
           "ORIGINAL_PRESENT_VALUE"
    FROM
    select   0-fssPV.feed_id                        as "parent_level_id",
             fssPV.feed_description                 as "parent_level_name",
             fssPV.book_id                          as "child_level_id",
             fssPV.book_display_name                as "child_level_name",
             fssPV.parent_scenario_id               as "scenario_id",
             fssPV.scenario_display_name            as "scenario_name",
             nvl(sc.exported, 'N')                  as "exported",
             nvl(fssPV.parent_regressed_cob_date,  fssPV.parent_cob_date)    as "regress_cob",
             fssPV.scn_status_id                    as "scn_status_id",
             fssPV.tgt_scenario_display_name        as "tgt_scenario_name",
             fssPV.load_status_id                   as "load_status_id",
             count(*)                               as "load_count",
            sum(fssPV.present_value)                as "PRESENT_VALUE",
             sum(fssPV.delta)                       as "DELTA",
             sum(fssPV.gamma)                       as "GAMMA",
             sum(fssPV.vega)                        as "VEGA",
             sum(fssPV.present_value) - sum (srbase.present_value) as "PNL",
                select SUM(vsr.original_present_value)
                from validated_position vp , validated_scenario_result vsr
                where
                VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
                AND VSR.COB_DATE= fssPV.cob_date
                and vsr.validated_position_id= vp.validated_position_id
                 AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                           FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                    marsnode mn
                                           WHERE    nodeIds.column_value = mn.node_id
                                           AND      mn.close_date is null
             ) "ORIGINAL_PRESENT_VALUE"
    from   (
    select fssTgts.*,
           mntgt.display_name        as "TGT_SCENARIO_DISPLAY_NAME",
           mnscenario.display_name   as "SCENARIO_DISPLAY_NAME",
           mnbook.display_name       as "BOOK_DISPLAY_NAME",
           fs.feed_description,
           sr.present_value,
           sr.delta,
           sr.gamma,
           sr.vega,
           p.position_id
    from (
    /** Treewalk to find Feed/Scenario dependencies **/
    Select fssBooks.feed_id,
           fssLinks.cob_date,
           fssLinks.scenario_id,
           fssBooks.load_status_id,
           fssBooks.scn_status_id,
           fssBooks.tgt_scenario_id,
           fssBooks.book_id,
           fssBooks.regressed_cob_date,
           fssLinks.feed_instance_id,
           fssLinks.parent_cob_date,
           fssLinks.parent_tgt_scenario_id,
           fssLinks.parent_regressed_cob_date,
           fssLinks.parent_scenario_id,
           fssLinks.parent_feed_instance_id
    from   (
    /** Treewalk (backwards) to find underlying data over FSS control table **/
    WITH fss AS
             /* Initial filter on feed_scenario_status for peformance           */
             /* cannot filter on scenario as we don't know the dependencies yet */
             ( select DISTINCT scenario_id,
                      f.cob_date,
                      f.scn_status_id,
                      f.regressed_cob_date,
                      f.tgt_scenario_id,
                      f.feed_id,
                      f.feed_instance_id
               from   feed_scenario_status f,
                      feed_group_xref fgx
               where    cob_date <= l_cobdate -- PVs for this cob must be loaded either today, or its regressed to a previous cob
               and    f.feed_id = fgx.feed_id
               and    fgx.feed_group_id like l_feed_group_id
               and    fgx.feed_id like l_feed_id
      select   feed_instance_id,
               scenario_id,
               prior scenario_id,
               cob_date,
               feed_id,
               scn_status_id,
               regressed_cob_date,
               /* Need to maintain the root values to identify the scenarios that users are seeing */
               CONNECT_BY_ISLEAF "ISLEAF",
               CONNECT_BY_ROOT scenario_id        as "PARENT_SCENARIO_ID",
               CONNECT_BY_ROOT feed_id            as "PARENT_FEED_ID",
               CONNECT_BY_ROOT cob_date           as "PARENT_COB_DATE",
               CONNECT_BY_ROOT tgt_scenario_id    as "PARENT_TGT_SCENARIO_ID",
               CONNECT_BY_ROOT regressed_cob_date as "PARENT_REGRESSED_COB_DATE",
               CONNECT_BY_ROOT feed_instance_id   as "PARENT_FEED_INSTANCE_ID"
      from     fss
      start with fss.cob_date = l_cobdate
      connect by (prior fss.regressed_cob_date = fss.cob_date and
                  prior fss.scenario_id = fss.scenario_id and
                  prior fss.feed_id = fss.feed_id and
                  prior fss.tgt_scenario_id is null
                 ) -- Connect if regressed (rule: same feed/book/scenario, different cob)
              or (prior fss.tgt_scenario_id = fss.scenario_id and
                  prior fss.cob_date = fss.cob_date and
                  prior fss.feed_id = fss.feed_id and
                  prior fss.feed_instance_id = fss.feed_instance_id
                 ) -- and connect if paste as (rule: same feed/cob/book, different scenario)
      ) fssLinks,
      feed_scenario_status fssBooks
    where isLeaf = 1
    and   fssLinks.parent_feed_id = fssBooks.feed_Id
    and   fssLinks.parent_cob_date = fssBooks.cob_date
    and   fssLinks.parent_scenario_id = fssBooks.scenario_id
    ) fssTgts,
    position p,
    scenario_result sr,
    marsnode mntgt,
    marsnode mnbook,
    marsnode mnscenario,
    feed_static fs
    where fssTgts.feed_id = fs.feed_id
    and   fssTgts.parent_tgt_scenario_id = mntgt.node_id (+)
    and   mntgt.close_date (+) is null
    and   fssTgts.feed_instance_id = p.feed_instance_id
    and   fssTgts.book_id = p.book_id
    and   fssTgts.cob_date = sr.cob_date
    and   fssTgts.scenario_id = sr.scenario_id
    and   p.feed_instance_id = sr.feed_instance_id
    and   p.position_id = sr.position_id
    and   p.book_id = mnbook.node_id
    and   mnbook.close_date is null
    and   fssTgts.parent_scenario_id = mnscenario.node_id
    and   mnscenario.close_date is null
    ) fssPV
    left outer join scenario_control sc
      on fssPV.parent_feed_instance_id = sc.feed_instance_id
      and upper(fssPV.scenario_display_name) = upper(sc.scenario)
    /* Join to SBM to calculate P&Ls */
    left outer join scenario_base_map sbm
      on  fssPV.scenario_id = sbm.scenario_id
      and sbm.begin_cob_date <= l_cobdate
      and sbm.end_cob_date > l_cobdate
    left outer join scenario_result srbase
      on  fssPV.cob_date = srbase.cob_date
      and fssPV.feed_instance_id = srbase.feed_instance_id
      and nvl(sbm.mapped_scenario_id, l_original_scn_id) = srbase.scenario_id
      and fssPV.position_id = srbase.position_id
    /* Only display (root) scenarios that users have selected */
    where fssPV.parent_scenario_id in (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                       FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                marsnode mn
                                       WHERE    nodeIds.column_value = mn.node_id
                                       AND      mn.close_date is null
    group by fssPV.feed_id,
             fssPV.feed_description,
             fssPV.book_id,
             fssPV.book_display_name,
             fssPV.parent_scenario_id,
             fssPV.scenario_display_name,
             sc.exported,
             fssPV.parent_regressed_cob_date,
             fssPV.scn_status_id,
             fssPV.tgt_scenario_display_name,
             fssPV.load_status_id,
             fssPV.parent_cob_date
    --         fssPV.feed_instance_id,
    --         fssPV.cob_date
    );In this query for the initial section where I am selecting the "ORIGINAL_PRESENT_VALUE" part
                select SUM(vsr.original_present_value)
                from validated_position vp , validated_scenario_result vsr
                where
                VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
                AND VSR.COB_DATE= fssPV.cob_date
                and vsr.validated_position_id= vp.validated_position_id
                 AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
                                           FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
                                                    marsnode mn
                                           WHERE    nodeIds.column_value = mn.node_id
                                           AND      mn.close_date is null
             ) "ORIGINAL_PRESENT_VALUE" Even though fssPV.feed_instance_id and fssPV.cob_date are not used anywhere in the SELECT clause requires tobe added to the final GROUP BY clause else
    the query though compiles successfully doesnt executes giving "Not a group by " error.
    Can anyone tell me why this is the problem and why these columns need to be added to the final GROUP BY clause.
    Rgds,
    Aashish

    Hi, Aashish,
    Aashish S. wrote:
    Even though fssPV.feed_instance_id and fssPV.cob_date are not used anywhere in the SELECT clause requires tobe added to the final GROUP BY clause else
    the query though compiles successfully doesnt executes giving "Not a group by " error.Actually, you are using both of those columns in the SELECT clause, when you compute original_present_value:
    select SUM(vsr.original_present_value)
    from validated_position vp , validated_scenario_result vsr
    where
    VSR.FEED_INSTANCE_ID= fssPV.feed_instance_id
    AND VSR.COB_DATE= fssPV.cob_date
    and vsr.validated_position_id= vp.validated_position_id
    AND vsr.scenario_id in  (SELECT   distinct mn.node_id as "SCENARIO_ID"
    FROM     TABLE(pack_scenarios_overview.splitInListIntoLeaves(a_scenario_list, '$', l_cobdate)) nodeIds,
    marsnode mn
    WHERE    nodeIds.column_value = mn.node_id
    AND      mn.close_date is null
    ) "ORIGINAL_PRESENT_VALUE" Since the scalar sub-query is correlated to fsspv.feed_instance_id and fsspv.cob_date, it is depenedant on those columns, the same as, say TRUNC (fsspv.cobb_date, 'YEAR') is depenedant on fsspv.cob_date.
    Perhaps you need to put SUM in the main query, not the scalar sub-query, or (probably faster) replace the scalar sub-query with a join. Without knowing your tables, or the results you want from your data, I can't say more.
    Whenever you have a problem, post a little sample data (CREATED TABLE and INSERT statements for all tables), and the results you want from that data.
    Simplify the problem as much as possible. In this case, I think you can show what the problem is using just two tables, the ones aliases fsspv and mn.
    If you can illustrate your problem using commonly available tables, like those in the scott schema, then you don't have to post any data; just the results you want.
    It looks like you're doing something like this:
    SELECT       job
    ,       COUNT (*)     AS cnt
    ,       (          -- Begin scalar sub_query to compute min_loc
                SELECT     MIN (loc)
              FROM     scott.dept
              WHERE     deptno     = e.deptno
           ) min_loc     -- End scalar sub_query to compute min_loc
    FROM       scott.emp     e
    GROUP BY  job
    ,            deptno     -- Omitting this causes ORA_00979: not a GROUP BY expression
    ;when you really should be doing something like this:
    SELECT       job
    ,       COUNT (*)     AS cnt
    ,       MIN ( (          -- Begin scalar sub_query to compute min_loc
                SELECT     loc
              FROM     scott.dept
              WHERE     deptno     = e.deptno
               ) ) min_loc     -- End scalar sub_query to compute min_loc
    FROM       scott.emp     e
    GROUP BY  job
    ;to get these results:
    JOB              CNT MIN_LOC
    CLERK              4 CHICAGO
    SALESMAN           4 CHICAGO
    PRESIDENT          1 NEW YORK
    MANAGER            3 CHICAGO
    ANALYST            2 DALLAS

Maybe you are looking for