Change JDBC select SQL query's where clause at runtime

Hi,
I have one JDBC sender channel with Select SQL Query which helps in fetching data from JDE table. We have defined where clause to fetch some particular records i.e. if ABC = NULL then fetch the record.. and then update query is used to turn that flag to "Y" i.e. ABC ="Y" so that next time the channel don't pick the same records again.
Now the problem is that if we want to fetch some records again whose flag has been set to "Y" we cannot change the select query again and again in the production environment.
Is there any way to change the select query of the JDBC channel at runtime e.g. Picking up some flat file where the conditions for the particular records to be picked are defined (ID=123) and changing the WHERE clause of select query in the JDBC channel for those records to be picked without using BPM.
Thank you!
With regards,
Simran

Hi Simran,
Yes, it is possible with the help of store procedure. In SQL Server there is a IF-Else Conditional block, which you can use inside store procedure. Create a SP with 2 additional parameter something like FlagReadAgain and KeyField. Pass the flag always as True or False. For the Key field pass the record key which you want to read again if you are passing the Flag as True else pass it as 0 or whatever.
In the procedure check if the value of flag is True -> If yes, Read the entry with key name specified in where part.
In the else part put the query which you are using for the normal flow.
IF (FlagReadAgain) = TRUE
BEGIN
   SELECT EmpName, EmpAddress
   FROM Employee
   WHERE EmpID = 'E001'
END
ELSE
   BEGIN
     SELECT EmpName, EmpAddress
     FROM Employee
     WHERE Status = 'N'
   END
You may also use the approach which Srini mentioned. Create an application to restore any value to intial stage so that it can be picked up by XI when it poll again.
Choose any approach which you like.
Regards,
Jitender Chauhan

Similar Messages

  • Simple finder results in huge slow sql query -- why WHERE clause?

    Hi all,
    wondering about the poor performance of my finder methods I took a look into the SQL that went to the database.
    "SELECT DISTINCT OBJECT(p) FROM Person p"
    results in
    SELECT PersonID, FirstName, LastName, [etc.] FROM person WHERE (PersonID='5354B71CC0A80113008BD3BB11A57FA1') OR (PersonID='5354B893C0A80113008BD3BB3C6918FF') OR (PersonID='5354B910C0A80113008BD3BBC83093BE') OR [etc.]
    where all 2000 primary keys are listed. This query costs ~ 4 seconds on my box.
    A query without WHERE costs ~ 0 seconds. So why this "WHERE" clause?
    Is this a JBoss specific problem? I am using version 3.2.3.
    thanx!
    Marcus

    It's not a bug - it's how JBoss implements it's own
    "findAll" methodology. Whether it's a good
    implementation or not is open to debate.Really strange.
    Anyway all my performance problems disappeared with setting the read-ahead strategy to "on-find". Although I don't fully understand why.
    Marcus

  • Query using where clause

    I am not able to run a SQL query using where clause.
    the query is as follows:
    I extract the text input by the user in a text field say 'a' and
    store it in string 'y'.
    String y= a.getText();
    //running the query
    Select A from B where B.x=y;
    how do we run a where clause when y is a string variable instead of value?

    Use the following :
    String y = a.getText();
    String query ="select A.CODE from Port A where A.NAME=" + "'" + y + "'" ;
    ResultSet rs= stmt.executeQuery(query);

  • How To change the ADF View Object  query where-clause at RunTime?

    I am trying to create a simple display page which will display user data (username, assoc_dist_id, assoc_agent_id, status , etc). The User data is stored in a database table and i am using an ADF Read Only table based on the View Object to display the data on the JSF page.
    However, i want to display only the users that a particular person accessing the page has the AUTH LEVEL to see. e.g. If the person accessing the page is an 'ApplicationAdministrator' then the page should display all users in the table, If its a 'DistributorAdministrator' then the page should display only users associated with that Distributor (i.e. assoc_dist_id = :p_Dist_id ) and If its an 'AgentAdministrator' , then the page should display only users associated with that Agent ( i.e. assoc_agent_id = :p_Agent_id).
    Currently my af:table component displays all the users in the table because the query for the view object is (select * from users) . However, i want to use the same viewobject and just set the where-clause at runtime with the appropriate parameter to restrict the dataset returned.
    Do anyone knows how to accomplish this ?

    David,
    See the custom method initializeDynamicVariableDefaults() in the SRViewObjectImpl.java class in the FrameworkExtentions project in the SRDemoSampleADFBC sample application. You can find out how to install the demo if you haven't already from the ADF Learning Center at:
    http://www.oracle.com/technology/products/adf/learnadf.html
    This class is a framework extension class for view objects that adds a neat, generic feature to be able to dynamic default the value of named bind variables. You can read more about what framework extension classes are and how to use them in Chapter 25, "Advanced Business Components Techniques" of the ADF Developer's Guide for Forms/4GL Developers, also available at the learning center above.
    It is an example of generic framework functionality that "kicks in" based on the presence of custom metadata properties on a named bind variable. See section 25.3.3 "Implementing Generic Functionality Driven by Custom Properties" in the dev guide for more details. Using this sample code, if you add a bind variable to a view object, and define a custom metadata property named "DynamicDefaultValue" on that bind variable, and set this custom metadata property to the value "CurrentUser", then that bind variable will have its value dynamically defaulted to the name of the authenticated user logged in. If instead you set this custom property to the value "UserRole", then the bind variable will be set to the comma-separated string containing the list of roles that the authenticated user is part of.
    Once you've created a framework extension class for view objects like this, you can have the view objects you create inherit this generic functionality.See section 25.1.4 "How to Base an ADF Component on a Framework Extension Class" in the dev guide for more info on this.
    By adapting a technique like this (or some idea similar that better suits your needs) you can have your view object query contain bind variables whose values automatically take on the defaults based on something in the user-session environment.

  • Can a recursive sql have a where clause

    can the following sql have a where clause and I dont want to hard code the id is is that possible...
    select DISPLAY_NAME, ID, PARENT_ID, display_in_parent_folder, sub_folder_sequence
    from wwsbr_all_folders start with id = 8888
    connect by prior id= parent_

    actually g is another alias I created sorry I missed it... if I do this as a regular sub query I get three records but when I implement it as a recursive query it does not retutn any thing. Below is my regular query followed by the recursive query which I am using to organize the result but get no results:
    REGULAR Query that retrieves records with parent_id = from the list of parent ids
    select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
    from WWSBR_ALL_FOLDERS f, WWSBR_ALL_FOLDERS g
         where g.parent_id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
    where
         e.caid = 103 AND
    e.parent_id <> 0 AND
    e.type_id = 1 AND
    e.display_in_parent_folder <> 0 AND
         e.id = f.parent_id)
    order by f.id, f.sub_folder_sequence;
    Recursive query that results nothing:
    select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
    from WWSBR_ALL_FOLDERS g, WWSBR_ALL_FOLDERS f start with f.id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
    where
         e.caid = 103 AND
    e.parent_id <> 0 AND
    e.type_id = 1 AND
    e.display_in_parent_folder <> 0 AND
         e.id = f.parent_id)
         connect by prior f.id= g.parent_id
    order by f.id, f.sub_folder_sequence;

  • How to get resultset from procedure having dynamic select sql query ?

    Hi,
    I have created a procedure, in which there is dynamic select query. The procedure has one out put parameter which gives error code. When I compile that procedure it compiles successufully. When I run it it executes successfully and gives output error code. But I don't know how to get resultset of that dynamic select sql query. I need that.
    This is the procedure:
    create or replace
    PROCEDURE uspGetProductDetailsMultiOrder
      v_DefinitionDBName IN VARCHAR2,
         v_CommonDBName IN VARCHAR2,
         v_Filter_FilledStatus IN VARCHAR2,
         v_Filter_Internal_Counterparty IN nvarchar2,
         v_Filter_NoteType IN nvarchar2,
         v_Filter_Exchange IN nvarchar2,
         v_Filter_Issuer IN nvarchar2,
         v_Filter_Product_Category  IN VARCHAR2,
         v_DateToFilter IN VARCHAR2,     
         v_Filter_FromDate IN VARCHAR2,
         v_Filter_ToDate IN VARCHAR2,
         v_Active_YN_Flag IN NVARCHAR2,
         v_Entity_ID IN NVARCHAR2,
         v_ErrorNumber  OUT NUMBER
       as
       v_SelectSQL  nvarchar2(32767);
          v_Setting_Name  nvarchar2(32767);
       v_Default_Value  nvarchar2(32767);
       v_Config_Value  nvarchar2(32767);
       v_CCY_ID  NUMBER(10,0);
       v_CCY_Data  nvarchar2(32767);
       v_CCY_List  nvarchar2(32767);
       v_Seq_Id  NUMBER(10,0);
       SWV_Active_YN_Flag NVARCHAR2(1);
       SWV_VarStr long;--varchar2(4000);
       SWV_TRANCOUNT NUMBER(10,0);
        SWV_fnc_SplitString_Id_var1 NUMBER(10,0);
       SWV_fnc_SplitString_Id_var0 NUMBER(10,0);
      CURSOR RestrictTermsheetVisibilityByC 
       IS select CS.Setting_Name,Default_Value,Config_Value
       from Config_Settings CS   LEFT OUTER JOIN Entity_Config EC  ON EC.Setting_ID = CS.Setting_ID
       where EC.Entity_ID = v_Entity_ID AND Setting_Level = 'ENTITY';
       CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,','));
       --CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id,Data FROM imp;
       CURSOR GetRestrictTemplateListCursor 
      -- is select id,data from imp;
       IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,',')) ;
         --Parikshit 18-Jul-2010, active YN flag param added in SP
    BEGIN
    SWV_Active_YN_Flag := v_Active_YN_Flag;
       if SWV_Active_YN_Flag = ' '  then
          SWV_Active_YN_Flag := 'Y';
       end if;
       v_SelectSQL := ' ';
       v_SelectSQL := v_SelectSQL || ' Select ';
       v_SelectSQL := v_SelectSQL || '  NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency';
         --SET @SelectSQL = @SelectSQL + ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN  NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN  NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield,  NOP.Dealer_Cost_PA as Internal_Cost '
       v_SelectSQL := v_SelectSQL || ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = ''Y'') THEN  NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = ''Y'') THEN  NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield,  NOP.Dealer_Cost_PA as Internal_Cost ';
       v_SelectSQL := v_SelectSQL || ' , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount,  NM.Active_YN_Flag, NM.Verify_YN_Flag ';
       v_SelectSQL := v_SelectSQL || ' , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At,  NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer';
       v_SelectSQL := v_SelectSQL || ' , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount ';
         --Added by Parikshit on 14-Jun-2011, to remove the unwinding amounts from the total issue size
         --SET @SelectSQL = @SelectSQL + ' , NOP.LastTimeWhenProductModified,NOP.Nominal_Amount as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty  '
       v_SelectSQL := v_SelectSQL || ' , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty  ';
         --********************************************************END
       v_SelectSQL := v_SelectSQL || ' ,T2.Confirmed_Amount, T2.Confirmed_Shares';
       v_SelectSQL := v_SelectSQL || ' , T3.Live_Deals';
       v_SelectSQL := v_SelectSQL || ' , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL   ';
       v_SelectSQL := v_SelectSQL || ' , ( case    When UPPER(NM.PreHedged_YN) = ''Y'' Then ''Launched'' ';
       v_SelectSQL := v_SelectSQL || '              When ((NM.Maturity_Date IS  NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then ''Matured''';
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NOT NULL)  Then ''Launched''';     
         --Ready to launch
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND  to_date(Close_Date) > to_date(sysdate) ) Then ''Ready To Launch''';     
         --Ready to launch
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND  to_date(Close_Date)= to_date(sysdate)    )  Then ''Ready To Launch''';     
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND  to_date(Close_Date)< to_date(sysdate)    )  Then ''Ready To Launch''';     
         --Warning trigger reached
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS  NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning ))  Then ''Warning Trigger Reached''';          
       v_SelectSQL := v_SelectSQL || '              Else ''Not Ready'' ';
       v_SelectSQL := v_SelectSQL || '              End)Launch_Status';
       v_SelectSQL := v_SelectSQL || ' , NI.Issuer_Code';
          v_SelectSQL := v_SelectSQL || ' , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront,   case when UPPER(NM.PreHedged_YN) = ''Y'' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge';
          v_SelectSQL := v_SelectSQL || ' , NOP.Hard_Margin  as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class ';
          v_SelectSQL := v_SelectSQL || '  , NM.Note_Product_Rating as Product_Rating,  NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count,  nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID,  ( (case when NM.Note_Order_Type = '''' then N''Market'' else NM.Note_Order_Type end )  ) as  Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,''Atmaturity'') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,''N'') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
    Note_Premium_PC  ';
       v_SelectSQL := v_SelectSQL || '  , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as  Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, ''Product'' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
    NM.NM_Counterparty_Upfront,  NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate ';
       v_SelectSQL := v_SelectSQL || ' from ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName|| '.Note_Master NM  ';
       v_SelectSQL := v_SelectSQL || 'Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Master NI ';
          v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when  ISNUMERIC(NM.Issuer) = 0  then  cast (NI.Issuer_Name as nvarchar2(25))  else  cast(NI.Issuer_Id as nvarchar2(25)) end )';     
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Order_Product NOP ';
       v_SelectSQL := v_SelectSQL || ' On NOP.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_DefinitionDBName||'.AssetDef AD ';
       v_SelectSQL := v_SelectSQL || ' On AD.Code = NM.Asset';
         v_SelectSQL := v_SelectSQL || ' AND AD.TypeAsset  = substr(NM.Note_Asset_Class,1,2) ';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Parameter IP ';
          v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when  ISNUMERIC(NM.Issuer) = 0  then  cast (IP.Issuer_Name as nvarchar2(25))  else  cast(IP.Issuer_Id as nvarchar2(25)) end )';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Template_Master TM ';
       v_SelectSQL := v_SelectSQL || ' On  TM.Template_Id =  NM.Template_ID ';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Scheme_Codes SC ';
       v_SelectSQL := v_SelectSQL || ' On  SC.Scheme_Alias =  NM.Type';     
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Counterparty_Master CM ';
       v_SelectSQL := v_SelectSQL || ' On  CM.CM_ID =  NM.Counterparty';     
          v_SelectSQL := v_SelectSQL || ' Left Outer Join      ';
       v_SelectSQL := v_SelectSQL || ' ( ';
       v_SelectSQL := v_SelectSQL || ' Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Deals ';
       v_SelectSQL := v_SelectSQL || ' where Prematurity_Date IS NOT NULL';
       v_SelectSQL := v_SelectSQL || ' AND (UPPER(Deletion_Reason ) = ''PART REDEMPTION'' or UPPER(Deletion_Reason ) = ''FULL REDEMPTION'')';
       v_SelectSQL := v_SelectSQL || ' Group by Note_master_ID ';
       v_SelectSQL := v_SelectSQL || ' ) ND ';
       v_SelectSQL := v_SelectSQL || ' On  ND.Note_Master_ID =  NM.Note_Master_ID';
    if  (v_Filter_FilledStatus = ' ' OR UPPER(v_Filter_FilledStatus) = 'ALL' ) then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NOP.Filled_Status IN (' || v_Filter_FilledStatus  || ')';
       end if;                         
         --AND NOP.Internal_Counterparty = 'DEFAULT''
       if(SUBSTR(to_char(v_Filter_Internal_Counterparty),1,4000)= ' ')  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NOP.Internal_Counterparty IN (' || v_Filter_Internal_Counterparty || ')';
       end if;                    
         --SET @SelectSQL = @SelectSQL + ' --Filter--'
       v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN ';
       v_SelectSQL := v_SelectSQL || ' (';
       v_SelectSQL := v_SelectSQL || '   select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares)  As Confirmed_Shares  ';
       v_SelectSQL := v_SelectSQL || '   from '||v_CommonDBName||'.Note_Order_RM  ';
       v_SelectSQL := v_SelectSQL || '   Where substr(UPPER(Order_Status_Flag),1,6) = ''YYYYYY'' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = ''N'' ';
       v_SelectSQL := v_SelectSQL || '   group by  Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' ) T2';
       v_SelectSQL := v_SelectSQL || ' ON T2.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN';
       v_SelectSQL := v_SelectSQL || ' (';
       v_SelectSQL := v_SelectSQL || '   Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals ';
       v_SelectSQL := v_SelectSQL || '   from '||v_CommonDBName||'.Note_Deals ND  ';
       v_SelectSQL := v_SelectSQL || '   where ND.Active_YNFlag = ''Y'' ';
       v_SelectSQL := v_SelectSQL || '   group by  Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' ) T3';
       v_SelectSQL := v_SelectSQL || ' ON T3.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  LEFT OUTER JOIN';
       v_SelectSQL := v_SelectSQL || '  (';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT))  Net_Trade_Hedged,';
       v_SelectSQL := v_SelectSQL || '  (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT))  Net_Trade_Outstanding,';
       v_SelectSQL := v_SelectSQL || '  SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY,';
       v_SelectSQL := v_SelectSQL || '  SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY,';
       v_SelectSQL := v_SelectSQL || '  SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  From';
       v_SelectSQL := v_SelectSQL || '  (';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  FROM '||v_CommonDBName||'.Note_Hedge  ';
       v_SelectSQL := v_SelectSQL || '  WHERE NH_Direction = ''BUY'' ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  Union';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  FROM '||v_CommonDBName||'.Note_Hedge  ';
       v_SelectSQL := v_SelectSQL || '  WHERE NH_Direction = ''SELL''  ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  ) ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  ) BS';
       v_SelectSQL := v_SelectSQL || '  ON BS.NH_Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' Where NM.Verify_YN_Flag = ''Y'' ';
      v_SelectSQL := v_SelectSQL || ' AND NM.Active_YN_Flag = ''' || SWV_Active_YN_Flag || '''';
       if(SUBSTR(to_char(v_Filter_NoteType),1,4000) = ' ' OR UPPER(v_Filter_NoteType) = 'ALL' ) then
               v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Type IN (' || v_Filter_NoteType  || ')';
       end if;     
    IF UPPER(v_Entity_ID) <> 'ALL'  then
          OPEN RestrictTermsheetVisibilityByC;
          FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
          WHILE RestrictTermsheetVisibilityByC%FOUND   LOOP
         --2) Convert comma separated ccy (CNY,HKD,USD) string to single quote ccy with comma separated Ccy ('CNY','HKD','USD') string
             if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_CCY')  then
                if v_Config_Value is not null  then
              SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var0 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
                   IF (SWV_fnc_SplitString_Id_var0 > 0)  then
                        --print 'Before Single  quote separated ccy : ' + '''' + @Config_Value + ''''
                      v_Seq_Id := 0;
                      OPEN Get_RestrictCCY_List_Cursor;
                      FETCH Get_RestrictCCY_List_Cursor
                      INTO v_CCY_ID,v_CCY_Data;
                      WHILE Get_RestrictCCY_List_Cursor%FOUND   LOOP
                         if v_Seq_Id = 0  then
                            v_CCY_List := '''' || v_CCY_Data || '''';
                         else
                            v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
                         end if;
                         v_Seq_Id := v_Seq_Id+1;
                         FETCH Get_RestrictCCY_List_Cursor INTO v_CCY_ID,v_CCY_Data;
                      END LOOP;
                      CLOSE Get_RestrictCCY_List_Cursor;
                        --print 'After Single quote ccy : ' + @CCY_List
                      v_SelectSQL := v_SelectSQL || ' AND nvl(NM.Denomination_Ccy,NM.Currency) NOT IN (' || v_CCY_List   || ')';
                   end if;
                end if;
             end if;
    --3) Convert comma separated template (ELN,BELN,BELN_B) string to single quote template code with comma separated template ('ELN','BELN','BELN_B') string
             if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_SUBSCHEME')  then
                if v_Config_Value is not null then
          SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var1 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
                   IF (SWV_fnc_SplitString_Id_var1 > 0)  then
                      v_Seq_Id := 0;
                      OPEN GetRestrictTemplateListCursor;
                      FETCH GetRestrictTemplateListCursor
                      INTO v_CCY_ID,v_CCY_Data;
                      WHILE GetRestrictTemplateListCursor%FOUND 
                      LOOP
                         if v_Seq_Id = 0  then
                            v_CCY_List := '''' || v_CCY_Data || '''';
                         else
                            v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
                         end if;
                         v_Seq_Id := v_Seq_Id+1;
                         FETCH GetRestrictTemplateListCursor INTO v_CCY_ID,v_CCY_Data;
                      END LOOP;
                      CLOSE GetRestrictTemplateListCursor;
                   --print 'After Single quote template code: ' + @CCY_List
                      v_SelectSQL := v_SelectSQL || ' AND TM.Template_Code NOT IN (' || v_CCY_List   || ')';
                   end if;
                end if;
             end if;
             FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
          END LOOP;
          CLOSE RestrictTermsheetVisibilityByC;
       end if;
      if  (v_Filter_Exchange = ' ' OR UPPER(v_Filter_Exchange) = 'ALL')  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Exchange IN (' || v_Filter_Exchange  || ')';
       end if;                         
         --SET @SelectSQL = @SelectSQL + ' --AND NM.Issuer = 4'
      if  (v_Filter_Issuer = ' ' OR UPPER(v_Filter_Issuer) = 'ALL') then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Issuer IN (' || v_Filter_Issuer  || ')';
       end if;     
          if  v_Filter_Product_Category    = ' '  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND UPPER(NM.Note_Issuer_Type) IN (''' || v_Filter_Product_Category  || ''')';
       end if;          
       if UPPER(v_DateToFilter) = 'NA'  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          if UPPER(v_DateToFilter) = 'CLOSE_DATE'  then
             v_SelectSQL := v_SelectSQL || ' AND to_char( '|| v_DateToFilter || ') >= to_date(''' || v_Filter_ToDate ||  ''');
                             -- AND convert(smalldatetime,''' || v_Filter_ToDate || ''',106) ';
          else
             v_SelectSQL := v_SelectSQL || ' AND to_char(''' || v_DateToFilter || ''') BETWEEN to_date(''' || v_Filter_FromDate ||  ''') AND to_date(''' || v_Filter_ToDate || ''') ';
          end if;
       end if;
       v_SelectSQL := v_SelectSQL || ' Order by NM.Product_Name';
       SWV_VarStr := v_SelectSQL;
       DBMS_OUTPUT.PUT_LINE(SWV_VarStr);
       EXECUTE IMMEDIATE SWV_VarStr;
       IF SQLCODE <> 0  then
          GOTO ERROR_HANDLER;
       end if;
       IF SQL%rowcount > 0  then
          COMMIT;
          SWV_TRANCOUNT := SWV_TRANCOUNT -1;
       end if;     --Commit Transaction
       v_ErrorNumber := SQLCODE;
       RETURN;
       << ERROR_HANDLER >> v_ErrorNumber := SQLCODE;
       ROLLBACK;
       SWV_TRANCOUNT := 0;     --Rollback Transaction
       RETURN;
    END;Please suggest something. Thanks
    Edited by: BluShadow on 30-Nov-2011 11:00
    added {noformat}{noformat} tags for formatting of code.  Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Connecting to the database sample_adf_finiq_common.
    Select NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = 'Y') THEN NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = 'Y') THEN NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield, NOP.Dealer_Cost_PA as Internal_Cost , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount, NM.Active_YN_Flag, NM.Verify_YN_Flag , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At, NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty ,T2.Confirmed_Amount, T2.Confirmed_Shares , T3.Live_Deals , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL , ( case When UPPER(NM.PreHedged_YN) = 'Y' Then 'Launched' When ((NM.Maturity_Date IS NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then 'Matured' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL) Then 'Launched' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND to_date(Close_Date) > to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)= to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)< to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning )) Then 'Warning Trigger Reached' Else 'Not Ready' End)Launch_Status , NI.Issuer_Code , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront, case when UPPER(NM.PreHedged_YN) = 'Y' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge , NOP.Hard_Margin as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class , NM.Note_Product_Rating as Product_Rating, NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count, nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID, ( (case when NM.Note_Order_Type = '' then N'Market' else NM.Note_Order_Type end ) ) as Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,'Atmaturity') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,'N') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
    Note_Premium_PC , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, 'Product' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
    NM.NM_Counterparty_Upfront, NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate from Sample_ADF_finiq_Common.Note_Master NM Left Outer Join Sample_ADF_finiq_Common.Issuer_Master NI On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (NI.Issuer_Name as nvarchar2(25)) else cast(NI.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Note_Order_Product NOP On NOP.Note_Master_ID = NM.Note_Master_ID Left Outer Join Sample_ADF_finiq_Common.AssetDef AD On AD.Code = NM.Asset AND AD.TypeAsset = substr(NM.Note_Asset_Class,1,2) Left Outer Join Sample_ADF_finiq_Common.Issuer_Parameter IP On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (IP.Issuer_Name as nvarchar2(25)) else cast(IP.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Template_Master TM On TM.Template_Id = NM.Template_ID Left Outer Join Sample_ADF_finiq_Common.Scheme_Codes SC On SC.Scheme_Alias = NM.Type Left Outer Join Sample_ADF_finiq_Common.Counterparty_Master CM On CM.CM_ID = NM.Counterparty Left Outer Join      ( Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from Sample_ADF_finiq_Common.Note_Deals where Prematurity_Date IS NOT NULL AND (UPPER(Deletion_Reason ) = 'PART REDEMPTION' or UPPER(Deletion_Reason ) = 'FULL REDEMPTION') Group by Note_master_ID ) ND On ND.Note_Master_ID = NM.Note_Master_ID AND NOP.Internal_Counterparty IN (1) LEFT OUTER JOIN ( select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares) As Confirmed_Shares from Sample_ADF_finiq_Common.Note_Order_RM Where substr(UPPER(Order_Status_Flag),1,6) = 'YYYYYY' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = 'N' group by Note_Master_ID ) T2 ON T2.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals from Sample_ADF_finiq_Common.Note_Deals ND where ND.Active_YNFlag = 'Y' group by Note_Master_ID ) T3 ON T3.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( SELECT NH_Note_Master_ID, (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT)) Net_Trade_Hedged, (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT)) Net_Trade_Outstanding, SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY, SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL, SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY, SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL From ( SELECT NH_Note_Master_ID, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'BUY' GROUP BY NH_Note_Master_ID Union SELECT NH_Note_Master_ID, 0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL, 0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'SELL' GROUP BY NH_Note_Master_ID ) GROUP BY NH_Note_Master_ID ) BS ON BS.NH_Note_Master_ID = NM.Note_Master_ID Where NM.Verify_YN_Flag = 'Y' AND NM.Active_YN_Flag = 'Y' AND UPPER(NM.Note_Issuer_Type) IN ('Internal') AND to_char('16-oct-11') BETWEEN to_date('15-oct-11') AND to_date('17-oct-11') Order by NM.Product_Name
    V_ERRORNUMBER = 0
    Process exited.
    Disconnecting from the database sample_adf_finiq_common.
    here v_errornumber=0 is the output when i run it in oracle sql developer.

  • Sub-Select SQL query in Oracle BI Answers

    Hi
    What's the proper usage of Sub-Select SQL query in Oracle BI Answers Version Oracle Business Intelligence 10.1.3.2.1?
    I get [SQL_STATE: HY000] [nQSError: 10058] A general error has occured when trying to Sub Select query like:
    itemno = (SELECT MIN(orders.itemno) FROM mydatabase where rownum < 2 order by orders.itemno)

    Maybe the best is to create a new physical and logical object for your sub-select and join this with your current objects.

  • Hierarchical query with where clause

    Hi,
    How can I query hierarchically a query with WHERE clause? I have a table with three fields session_id,id and root_id.
    When I try with the following query,
    select id, level from relation
    where session_id = 79977
    connect by prior id = root_id start with id = 5042;
    It gets duplicate values.
    I want the query to show in the hierarchical manner with a filter condition using WHERE clause. Please help me how can I achieve this. If you know any link that describes more about this, please send it.
    Thanks in Advance.
    Regards,
    -Parmy

    Hi Sridhar Murthy an others,
    Thanks a lot for your/the answer. It's working for me. It saved a lot of other work around without the proper knowledge of hierarchical query. Please send me any link that describes these issues in detail and also I hope as I have mentioned in the other message, same cannot be achieved on views or ( on two different tables ???)
    Any way thanks for your reply,
    It's working for me.
    With happiness,
    -Parmy

  • Query Bean Where clause

    In Query Bean (Auto Customization Criteria) , OA FWK generate
    where clause automatically .
    I want to disable this criteria in some cases. Is there any way exists?
    (Disable means remove some condition )
    I want to see runtime query with where clause(In case of Query Bean) . Is there is any way to find out it?
    Thanks, Avaneesh

    You have couple of options to do this,
    1. You can use getCriteria API on the queryBean which will stop the query execution by framework and it's the responsibility of the developer to use the dictionary returned by getCriteria and bind the complete where clause yourself.
    2. You can use getNonViewAttrCriteria API on queryBean. This provides a dictionary of criteria on the column which are not mapped to a viewAttribute, for example if you want a poplist in the search region which has values like "Last one week", "Last 2 weeks", "Last 15 days" and so on and want to bind the criteria your self by interpreting the value selected.
    In this case, framework still binds the where clause for the other criteria's which are mapped to a vo based column in the table and expects the developer to bind the criteria for these non viewattribute mappings in the controller.
    I think your requirement fits in the second approach.

  • How to Use SQL Query having IN Clause With DB Adapter

    Hi,
    I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
    Thanks

    invoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter

  • Changing the JCA SQL query in runtime

    Hi,
    Is it possible to change the predefined sql query in JCA during runtime in OSB.
    Regards,
    Abdul

    Abdul,
    It won't be possible as structure of request and response is tightly coupled with the SQL and any update in SQL may also require corresponding update in XSD.
    Regards,
    Anuj

  • Hosting company does not support SQL query with OUTFILE clause

    From my mysql database, I want to allow the user to run a query and produce a csv / text file of our membership database.   Unfortunately,  I just found out my hosting company does not support the SQL query with OUTFILE clause for MySQL database.
    Are there any other options available to produce a file besides me running the query in phpadmin and making the file available to users.
    Thanks.  George

    Maybe this external Export Mysql data to CSV - PHP tutorial will be of help
    Cheers,
    Günter

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • SELECT QUERY CHECK & WHERE CLAUSE DIFFERENCE.URGENT PLEASE.

    My question is ,
    IF SBOOK_WA-CARRID = 'LH' CONDITION IS AGAIN PRESENT IN THE DATABASE TABLE ,,,,WILL THE CHECK CONDITION SEARCH IT AGAIN EVEN AFTER FINDING IT IN THE FIRST OF THE TABLE???OR SIMPLY TERMINATE IN THE FIRST TIME THE CONDITION SATISFIES??IF DOES TERMINATE THEN ERRONEOUS RESULT IS BOUND TO COME SINCE ONE MORE RECORS IS UNSELECTED.
    SIMILARLY DOES THE WHERE CLAUSE CONTINUE SEARCHING EVEN AFTER HAVING FOUND THE CONDITION ALREADY ONCE IN THE TABLE??
    PLEASE HELP ME IN THIS ASPECT.PLEASE CHECK THE TWO DIFFERENT CODES & ANSWER ACCORDINGLY..
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    SELECT * FROM SBOOK INTO SBOOK_WA
      WHERE CARRID = 'LH' AND
            CONNID = '0400'.
    ENDSELECT.

    Hi,
    The Check condition will be true, so it will not going to display the records, it will fill the internal table.
    In the Where condition it will fill the Internal table as well as it will display also.
    Hope now your query is solved
    Regards,
    Dhruv Shah

  • Pl/sql select distinct in a where clause

    Greedings,
    I am trying to execute some kind of distinct using rowid in where clause but for some reason im not getting the appropriate result. Any guidance is welcome
    SELECT acnt_code,cat,cat_desc,buc FROM so_budgets_cat where
    Trim(buc)='S03'
    and
    NOT exists (SELECT  1
                       from   so_budgets_cat tab2
                       where  (  tab2.cat     =  so_budgets_cat.cat )
                       and    tab2.ROWID  > so_budgets_cat.ROWID
    ORDER BY cat,so_budgets_cat.rowidThanks in advance

    Can you provide some example data and example output to further clarify?
    It might be that you want something like the code below, but it's hard to tell.
    SELECT acnt_code
    ,      cat
    ,      cat_desc
    ,      buc
    FROM
    (SELECT acnt_code
    ,      cat
    ,      cat_desc
    ,      buc
    ,      ROW_NUMBER() OVER (PARTITION BY cat ORDER BY <something>) rn
    FROM   so_budgets_cat
    WHERE  Trim(buc)='S03')
    WHERE rn = 1;

Maybe you are looking for

  • Automatic Clearing of GR-IR Clearing account

    Dear all In f.13 i am not able to do automatic clearing of rg-ir clearing account ,i am getting the massage no clearing procedures are carried out despite all selection criterial fulfilled . This is needed because i want only credit balances in GR/IR

  • I Deleted My Programs Trying to Deactivate the Trials. How Do I Get Them Back?

    I had downloaded trials of Photoshop, DreamWeaver, Lightroom and InDesign before finally purchasing a Creative Cloud subscription on Tuesday. In an attempt to try to get my application manager to recognize that I had purchased the Creative Cloud subs

  • Concurrent Manager Issue in Oracle Apps 11i on MS Windows 2003

    Hi, We have Oracle Apps 11i (11.5.10) on Windows 2003 running Oracle Financilas and Supply Chain. From this morning onwards, concurrent requests are not getting completed. All requests are showing Running Normally. I checked the server (Single Node 4

  • New rapport crashes CR when adding more than one table

    Hello SAP Community Network Forums. First post, so I hope I landed in the right place. If I create a new rapport and add more than 2 tables to the rapport, CR shutdown. The following error is generated: Event Type:     Error Event Source:     Applica

  • Transforming EPC to BPMN in Aris Business Architect 7.1

    I have read in the helpfilel for Business Architect that it is possible to transform from one type of diagram to another. It was also mentioned on the SAP BPM training that I have attended. However I am not able to find the function which will enable