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

Similar Messages

  • Need Plsql query

    hi
    I need oracle plsql query for this concept , which itemcode present in four month
    Eliminate less than 4 month itemcode
    Itemcode month id
    1000 144
    1000 148
    1000 152
    1000 156
    so on
    ---------- eliminate this types of items
    2000 144
    3000 148
    3000 156
    Note : please dont use Procedures

    785143 wrote:
    hi
    I need oracle plsql query for this concept , which itemcode present in four month
    Eliminate less than 4 month itemcode
    Itemcode month id
    1000 144
    1000 148
    1000 152
    1000 156
    so on
    ---------- eliminate this types of items
    2000 144
    3000 148
    3000 156
    Note : please dont use ProceduresAre you saying that the same itemcode has to be related to 4 (or more) different months?
    Here's one way to do that:
    WITH     got_cnt          AS
         SELECT     itemcode
         ,     month_id
         ,     COUNT (DISTINCT month_id) OVER (PARTITION BY  itemcode)     AS cnt
         FROM     table_x
    SELECT     itemcode
    ,     month_id
    FROM     got_cnt
    WHERE     cnt     >= 4
    ;If you mean something else (such as all the monthids have to be in a series, with a difference of 4 between successive monthids), then explain more clearly.

  • 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.

  • How to link a non-linkable query and a plsql query in the datamodel

    Hi,
    I am creating a matrix group....
    Where in I get my
    1) Column values from a non-linkable query - Period (Jan, Feb....)
    2) Row values from a plsql query (ref cursor). Group is also from this query
    3) Cross product is on the above two queries.
    4) Cell info comes from a plsql query (refcursor).
    I created a group link from the cross product group (3) to the cell info query (4)
    I prepared the layout and executed the report... I am getting redundant data....
    The reason being the (4) and (1) are not linked properly.
    From google, About non-linkable queries column.... I understood that to link two non-linkable queries, we need to create a group link and then add a where clause in the child query referring the parent query column.
    But my case is a non-linkable query (which is a parent ) and a plsql query which is the cell.
    Any help...?
    Thanks in advance.
    KK

    Hello Sam,
    >
    I was wondering if you could have any link or examples to show how to make a form with report and an insert form in the same page, these two forms are related to the same table. Our customer wants a user can add new row to the table in a form and see all of rows created by this user in a report, this report should provide edit link as well. the problem is: whenever I inserted a new row or edit a row or delete a row, and submitted, and return to this page, all of hidden items lost their values, so report is blank, and some display only items also lost their values. Could anyone give me suggestions?
    >
    This will help:
    http://www.grassroots-oracle.com/2011/09/apex-tutorial-form-report-sharing-same.html
    Hope it helps!
    Regards,
    Kiran

  • 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

  • Simple - plsql query

    I am new to plsql and want to do following in plsql code:
    code start select max(col1) from table1;
    -- and save the max value in variable VAR1
    select COL1, case COL2 when VAR1 THEN 'VALUE ONE'
    ELSE 'VALUE ELSE'
    END
    from table1
    -- I want to see the o/p of second select on the screen
    code ends how can i write the above plsql code.

    No, its not working... see the below..
    create table test5 as select owner, object_name, subobject_name, object_type from all_objects;
    create unique index test5_i5 on test5 (owner, object_name, subobject_name, object_type);
    select * from test5 where owner like 'SCOTT' AND OBJECT_NAME LIKE 'EMP';
    INDEX RANGE SCAN| TEST5_I5 | 4 | 248 | 1 (0)| 00:00:01 |
    but when i use
    select * from test5 where UPPER(OWNER) LIKE 'SCOTT%' AND UPPER(OBJECT_NAME) LIKE 'EMP%';
    TABLE ACCESS FULL| TEST5 | 3 | 186 | 65 (5)| 00:00:01 |
    i know it goes to full scan, i want to know is there any other way to make index used .. without using functional based indx...
    the reason is user can search any one of the column data and data is mixed case in table columns and/or conditions specified in query..
    .. any help...
    not sure how to use 'NLS_SORT=BINARY_CI' on multicolumn index and enable index used in search operation.. ANY OTHER WAY OF DOING THIS...
    requirements is
    mixed (lower,upper) data stored in db columns and mixed case data searched, 5 columns specified in where condition, data may be provided in search conditon to one or two or to all 5 columns in mixed case... matching records need to be returned.. suggest a good way of doing this... thnx

  • 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

Maybe you are looking for

  • GR/IR clearing account in open items in MR11

    Dear Experts , In MR11 , the GR/IR clearing account is showing as an open item despite the the fact that credit entries in GR are knocked off in invoice . If I check the GL balance it is showing debit & credit entried properly . But still in MR11 it

  • How can I delete all these mysteriously empty albums

    I need to clean out the photos and folders/albums which are in my iPad "Photo" app (NOT iPhoto). For some reason, at some point, folders/albums which previously held photos seem to be empty and grayed out. I want to delete them. I click "Edit" but wh

  • How does a public/private key encrypt and decrypt each other?

    I understand the logic that when a communication takes place both parties pass their public keys to each other which is used to encrypt all messages. Once the party receives the messages the private key is used to decrypt them however I'm wondering h

  • To find all the child records are processed before parent records

    Hi, When i am trying to process consignment pulls and my client is using third party tool to insert the data into interface tables. My logic is written in such a way that it should pick parent record associated with child but there is some delay in c

  • Install error on mac intel

    I am unable to install flash 9 on my intel mac. I have deleted firefox and its preferences. I have closed google desktop but still get the access denied message. Does anyone have any suggestions?