SQL Transform with VARIABLE

Hello!
I have the SQL Transform with global variable.
First, I have a script for iniciality the variable:
$DATE_CUST= to_date('2011/11/15 00:00:00.000','YYYY/MM/DD HH24:MI:SS.FF');
I print the variable, in the execution write:
2800     896     PRINTFN     2011.11.15 00:00:00.000000000
STEP in SQL Transforms: 
1.  SELECT * FROM TABLE_CUSTOMER
2.  PUSH the update Schema button
3.  add the where clause:  WHERE DATE_CUSTOMER > [$DATE_CUST]
4.  save the DataFlow.
When the execute the job, But we got error...  The variable is null or empty
In the log trace: 
|Data flow DF_VAR|Reader SQL
SELECT query <select * from TABLE_CUSTOMER
WHERE DATE_CUSTOMER  > 
The database error message is <Sybase SQL Server <CRMGCPSA> error message for operation <ct_results>: <Sybase ASE Server message number <102> State <1> Severity <15> From Server <ASEDWHD>:   Message Text is: Incorrect syntax near ')'.
>.
Why no have value the variable ?
The script correct should be
SELECT query <select * from TABLE_CUSTOMER
WHERE DATE_CUSTOMER  >  2011.11.15 00:00:00.000000000

Both braces and square brackets can be used to reference variables, however they behave slightly differently.
suppose I have the following hard-coded SQL statement
select * from al_funcinfo where name = 'avg'
Now I want to make it dynamic, I can use a variable and some square brackets
select * from al_funcinfo where name = '[$G_Name]'
or braces
select * from al_funcinfo where name = {$G_Name}
As you can see, braces adds single quotes around the varible value.  It is very useful when constructing complex statements requiring string values to be delimited with quotes (as most SQL DBs do).  These variable interpolation techniques can be used in scripts.
M

Similar Messages

  • Problems in SQL transform with variable in statement

    Hi,
    I have an sql transform with a variable in the statement. It looks like this:
    SELECT * FROM I.X where I.X.CUSTOMERNUMBER IN ([$variable])
    I have a script running prior which sets the $variable = '\'366800\',\'000933\'';
    (the CUSTOMERNUMBER field is a string)
    The problem is when DI compiles the SQL with the variable value, it is replacing each single quote with two single quotes, and thus turning my list of values into a single string (as recognised by DB2).
    How can I work around this? The CUSTOMERNUMBER field is indexed and the table is very large, so I want to use a very efficient statement to retrieve the data. I'm inserting this data into a different database, so I can't use the sql() function to execute the query and insert the rows into a new table in the same database (don't have authority to do that).
    I also need the sql to be dynamic because the customer numbers required will change from time to time. They're listed in another database and I plan on writing a loop to set the $variable value to contain all values in the lookup table, but I can't use that in a join because its in a different database and would not be efficient.
    Does anyone have any ideas? I'm literally all out, have tried a wide range of things to no avail, and none of my colleagues can work it out either.
    Thanks very much,
    -Steve

    I assume the SQL Transform is used only because of that in-list, not for other reasons....
    In this book page here: https://boc.sdn.sap.com/node/20046 at the very bottom it isdescribed on how to use the pushdown_sql() function in a where clause to add *any* text of your choice into the select statement DI generates. In this example I used a "where exists" but you can easily change the text to
    where key=5 and       pushdown_sql('my_datastore', 'CUSTOMERNUMBER IN ([$variable])')    and gender='M'
    I used the key=5 and gender=M just to clarify the syntax (I hope).
    For the SQL Transform, I wonder if you need the [$variable] syntax as well....

  • Cell Offload will Happen for pl/sql Block with variables

    Hello Experts,
    i am working on procedures on exadata now. i was confused with cell offload in exadata. somehow offload is not happening when i ran the sql statement in in pl/sql block with variables.
    here are my findings.
    when i ran insert into from select with values at toad, my query response time is very good. the total process is completed in less than a minute.
    i checked offload is happening.
    same sql statement is placed in plsql block with variable, procedure is taking lot of time and it is not completing. this case offload is not happening.
    is it true, if i use variables in pl/sql block will not use cell offload and smart scan?
    if yes, what is the work around.
    Thanks
    #! Pavan

    Hello Marc,
    Thanks for quick response.
    when i ran the query with literals in toad session i am getting response.
    when i run it with pl/sql block , block is not completing at all.
    here is the plsql block:
    My Apologies for sending big code,with out proper format.
    DECLARE
    P_BUSINESS_DATE DATE;
    P_BATCH_ID NUMBER;
    UTC_OFFSET NUMBER;
    BEGIN
    P_BUSINESS_DATE := to_date('02/01/2012', 'MM/DD/YYYY');
    P_BATCH_ID := 1;
    UTC_OFFSET := 0;
    INSERT /*+ APPEND */ INTO UPL_CLIENT_tbl
    ( reportdate,
    LastName,
    FirstName,
    MiddleInitial,
    AccountNumber,
    Address,
    City,
    State,
    Zip,
    HomePhone,
    WorkPhone,
    BirthDate,
    Age,
    Sex,
    NumberOfChildren,
    Occupation,
    LeadSource,
    Consultant,
    ProgramDirector,
    CallTaker,
    LeadDate,
    FirstVisitDate,
    LastVisitDate,
    BillType,
    ClientType,
    PreviousClientType,
    AppointmentDate,
    DoctorLetterRequired,
    OneYearPermStabilizationDate,
    UnlimitedPermStabilizationDate,
    MaritalStatus,
    ReferrerName,
    ReferrerCentreID,
    CentreID,
    PaymentDateOne,
    PaymentAmountOne,
    PaymentDateTwo,
    PaymentAmountTwo,
    PaymentDateThree,
    PaymentAmountThree,
    PaymentDateFour,
    PaymentAmountFour,
    LibraryPurchased,
    BalanceDue,
    FoodNSFBalance,
    ProductNSFBalance,
    ProgramNSFBalance,
    StartWeight,
    CurrentWeight,
    GoalWeight,
    Height,
    DateGoalWeightAchieved,
    DateSuccessPlusPurchased,
    ReturnToActiveDate,
    VersionNumber,
    HalfWayDate,
    LastLSCDate,
    LastUpdatedDate,
    VitaminWaiverSigned,
    LastSupplementPurchaseDate,
    LastSupplementCodePurchased,
    LastTotalSupplementSupplyCycle,
    LastAddtlSupplPurchaseDate,
    LastAddtlSupplCodePurchased,
    LastAddtlSupplSupplyCycle,
    DiabetesClient,
    DietControlled,
    TakingOralMed,
    TakingInsulin,
    EmailId,
    CTADate,
    RWLDate,
    Address2)
    (SELECT /*+ full(S_CONTACT) full(REFERRER) full(Consultant) full(ProgramDirector) full(CallTaker) full(S_CONTACT_X) full(a) full(a2) full (a3) */ distinct p_business_date reportdate,
    SUBSTR(S_CONTACT.LAST_NAME,1,25) AS LastName,
    SUBSTR(S_CONTACT.FST_NAME,1,25) AS FirstName,
    SUBSTR(S_CONTACT.MID_NAME,1,1) AS MiddleInitial,
    S_CONTACT.X_JC_ACNT_NUM + 900000000 AS AccountNumber,
    SUBSTR(S_ADDR_PER.ADDR,1,40) AS ADDRESS,
    SUBSTR(S_ADDR_PER.CITY,1,20) AS City,
    S_ADDR_PER.STATE AS State,
    SUBSTR(S_ADDR_PER.ZIPCODE,1,15) AS Zip,
    SUBSTR(REPLACE(S_CONTACT.HOME_PH_NUM,'-',''),1,10) AS HomePhone,
    SUBSTR(REPLACE(S_CONTACT.WORK_PH_NUM,'-',''),1,10) AS WorkPhone,
    S_CONTACT.BIRTH_DT AS BirthDate,
    CASE WHEN FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) < 0 THEN NULL ELSE FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) END AS AGE,
    S_CONTACT.SEX_MF AS SEX,
    NULL AS NumberOfChildren,
    S_CONTACT_X.ATTRIB_34 AS OCCUPATION,
    CASE WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Othe' THEN 'Othr'
    WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Inte' THEN 'Intr'
    WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Prin' THEN 'News'
    WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Gues' THEN 'Gst'
    ELSE SUBSTR(S_CONTACT_X.ATTRIB_37,1,4) END AS LeadSource,
    SUBSTR(Consultant.EMP_NUM,1,10) AS CONSULTANT,
    ProgramDirector.EMP_NUM AS ProgramDirector,
    CallTaker.EMP_NUM CallTaker,
    S_CONTACT.X_LEAD_DT AS LeadDate,
    LEAST(nvl(S_CONTACT.X_LAST_CONSULTATION_DATE,O.FirstPurchaseDate ), nvl(O.FirstPurchaseDate,S_CONTACT.X_LAST_CONSULTATION_DATE+1) ) AS FirstVisitDate, --X_LAST_CONSULTATION_DATE stores the performed date or the legacy client firstvisitdate
    GREATEST(nvl(S_CONTACT_XM.X_CONSULTATION_DT ,S_CONTACT_X.ATTRIB_29), nvl(S_CONTACT_X.ATTRIB_29, S_CONTACT_XM.X_CONSULTATION_DT-1) ) AS LastVisitDate,
    CASE WHEN S_CONTACT.X_INSTALLMENT_BALANCE > 0 THEN 'B' ELSE NULL END AS BillType,
    ct.current_client_type ClientType,
    SUBSTR(ct.saved_client_type,1,1) PreviousClientType,
    S_CONTACT.LAST_CREDIT_DT AS AppointmentDate,
    CASE WHEN a.X_DR_LETTER_STATUS IS NOT NULL THEN 'Y' ELSE 'N' END AS DoctorLetterRequired,
    NULL AS OneYearPermStabilizationDate,
    DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT ,NULL) AS UnlimitedPermStabilizationDate,
    SUBSTR(S_CONTACT.MARITAL_STAT_CD,1,1) AS MaritalStatus,
    SUBSTR(REFERRER.FST_NAME ||' '|| REFERRER.LAST_NAME,1,34) AS ReferrerName,
    ORGEXT_REF.LOC AS ReferrerCentreID,
    S_ORG_EXT.LOC AS CentreID,
    NULL AS PaymentDateOne,
    NULL AS PaymentAmountOne,
    NULL AS PaymentDateTwo,
    NULL AS PaymentAmountTwo,
    NULL AS PaymentDateThree,
    NULL AS PaymentAmountThree,
    NULL AS PaymentDateFour,
    NULL AS PaymentAmountFour,
    NULL AS LibraryPurchased,
    nvl(S_CONTACT.X_INSTALLMENT_BALANCE,0) + nvl(S_CONTACT.X_PREPAID_BALANCE,0) AS BalanceDue, -- Changed operation from (-) prepaid to (+) prepaid since the sign was flipped in OLTP.
    NULL AS FoodNSFBalance,
    NULL AS ProductNSFBalance,
    NULL AS ProgramNSFBalance,
    a2.X_START_WEIGHT AS StartWeight,
    a2.X_CURRENT_WEIGHT AS CurrentWeight,
    a2.X_GOAL_WEIGHT AS GoalWeight,
    a3.X_HEIGHT AS Height,
    a2.X_FAXSENT_DATETIME DateGoalWeightAchieved,
    DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT,NULL) AS DateSuccessPlusPurchased,
    CASE WHEN A2.ARCHIVE_FLG = 'N' THEN a2.START_DT ELSE NULL END AS ReturnToActiveDate,
    600 VersionNumber,
    a2.X_FAXRECV_DATETIME AS HalfWayDate,
    NULL AS LastLSCDate,
    TRUNC(S_CONTACT.LAST_UPD-UTC_OFFSET/24) AS LastUpdatedDate,
    NULL AS VitaminWaiverSigned,
    LastSupplementPurchaseDate,
    LastSupplementCodePurchased,
    LastTotalSupplementSupplyCycle,
    LastAddtlSupplPurchaseDate,
    LastAddtlSupplCodePurchased,
    LastAddtlSupplSupplyCycle,
    CASE WHEN (a.X_DIABETES_NO_MEDS_FLG='Y' OR a.X_DIABETES_ORAL_MEDS_FLG = 'Y' OR a.X_DIABETES_ON_INSULIN_FLG = 'Y') THEN 'Y' ELSE 'N' END AS DiabetesClient,
    DECODE(a.X_DIABETES_NO_MEDS_FLG,'Y','Y','N') AS DietControlled,
    a.X_DIABETES_ORAL_MEDS_FLG AS TakingOralMed,
    a.X_DIABETES_ON_INSULIN_FLG AS TakingInsulin,
    S_CONTACT.EMAIL_ADDR AS EmailId,
    NULL CTADATE,
    NULL RWLDATE,
    SUBSTR(S_ADDR_PER.ADDR_LINE_2,1,40) AS Address2
    FROM S_CONTACT,
    S_CONTACT REFERRER,
    S_CONTACT Consultant,
    S_CONTACT ProgramDirector,
    S_CONTACT CallTaker,
    S_CONTACT_X,
    (SELECT /*+ parallel full(S_CONTACT_XM) */ PAR_ROW_ID, attrib_05, MAX(X_CONSULTATION_DT) AS X_CONSULTATION_DT FROM S_CONTACT_XM
    WHERE (S_CONTACT_XM.last_upd_by < '1-14WD'
    or S_CONTACT_XM.last_upd_by > '1-14WD')
    AND S_CONTACT_XM.ATTRIB_05 IN (SELECT row_id FROM S_ORG_EXT WHERE S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) LOC IN (SELECT centreid FROM UPL_LIVE_CENTRES WHERE LIVE = 'Y' AND BATCHID = p_batch_id)) where S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) --
    GROUP BY PAR_ROW_ID, attrib_05) S_CONTACT_XM,
    (SELECT CONTACT_ID, ACCNT_ID,
    MAX(LastSupplementPurchaseDate) AS LastSupplementPurchaseDate,
    MAX(LastSupplementCodePurchased) AS LastSupplementCodePurchased,
    MAX(LastTotalSupplementSupplyCycle) AS LastTotalSupplementSupplyCycle,
    MAX(LastAddtlSupplPurchaseDate) AS LastAddtlSupplPurchaseDate,
    MAX(LastAddtlSupplCodePurchased) AS LastAddtlSupplCodePurchased,
    MAX(LastAddtlSupplSupplyCycle) AS LastAddtlSupplSupplyCycle,
    MIN(FirstPurchaseDate) AS FirstPurchaseDate,
    MAX(LastPurchaseDate) AS LastPurchaseDate
              FROM (
              SELECT /*+ parallel full(S_ORDER) full(S_ORDER_XM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
    NULL AS LastSupplementPurchaseDate,
    NULL AS LastSupplementCodePurchased,
    NULL AS LastTotalSupplementSupplyCycle,
    NULL AS LastAddtlSupplPurchaseDate,
    NULL AS LastAddtlSupplCodePurchased,
    NULL AS LastAddtlSupplSupplyCycle,
    (S_ORDER_XM.X_BUSINESS_DATE) FirstPurchaseDate,
    (S_ORDER_XM.X_BUSINESS_DATE) LastPurchaseDate
              FROM S_ORDER,S_ORDER_XM
              WHERE S_ORDER.ROW_ID = S_ORDER_XM.PAR_ROW_ID
              AND S_ORDER.STATUS_CD IN ('Complete', 'Submitted', 'Ready')
              AND TRUNC(S_ORDER_XM.X_BUSINESS_DATE - UTC_OFFSET/24) <= (p_business_date)
              --GROUP BY S_ORDER.CONTACT_ID
              UNION ALL
              SELECT /*+ parallel full(S_ORDER) full (S_ORDER_ITEM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN S_ORDER.CREATED ELSE NULL END) AS LastSupplementPurchaseDate,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 931 ELSE NULL END) AS LastSupplementCodePurchased,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 7 ELSE NULL END) AS LastTotalSupplementSupplyCycle,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN S_ORDER.CREATED ELSE NULL END) AS LastAddtlSupplPurchaseDate,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 920 ELSE NULL END) AS LastAddtlSupplCodePurchased,
              (CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 28 ELSE NULL END) AS LastAddtlSupplSupplyCycle,
              NULL FirstPurchaseDate,
              NULL LastPurchaseDate
              FROM S_ORDER,S_ORDER_ITEM, S_PROD_INT
              WHERE S_ORDER_ITEM.PROD_ID = S_PROD_INT.ROW_ID
                   AND S_ORDER.ROW_ID = S_ORDER_ITEM.ORDER_ID
                   AND S_ORDER_ITEM.qty_req <> 0
                   AND s_order.created_by <> '1-14WD'
                   AND S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
                   AND (S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
                   OR EXISTS (select 1 from S_ORDER_ITEM i2,s_prod_int p
    where i2.row_id = S_ORDER_ITEM.PAR_ORDER_ITEM_ID
    and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
    and i2.prod_id = p.row_id
                   AND S_ORDER.status_cd in ('Complete', 'Submitted', 'Ready')
                   and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
    GROUP BY CONTACT_ID,ACCNT_ID) O,
    S_CONTACT_TNTX,
    S_ORG_EXT,
    S_ORG_EXT ORGEXT_REF,
    S_ADDR_PER,
    S_ASSET a,
    S_PROD_INT,
    S_ASSET a2,
    S_ASSET a3,
    UPL_CLIENT_TYPES ct,
    (select /*+ parallel */ o.contact_id, o.accnt_id
    from S_ORDER o, S_ORDER_XM oxm
    where o.row_id = oxm.par_row_id
    and trunc(oxm.X_BUSINESS_DATE - (UTC_OFFSET/24)) = trunc(p_business_date)
    group by o.contact_id, o.accnt_id) oxm2
    WHERE S_CONTACT.ROW_ID = S_CONTACT_X.PAR_ROW_ID
    AND S_CONTACT_X.ROW_ID = S_CONTACT_XM.PAR_ROW_ID (+)
    AND (S_ORG_EXT.ROW_ID = S_CONTACT.PR_DEPT_OU_ID
    OR S_ORG_EXT.ROW_ID = oxm2.accnt_id
    OR S_ORG_EXT.ROW_ID = S_CONTACT_XM.attrib_05)
    AND ORGEXT_REF.ROW_ID(+) = REFERRER.PR_DEPT_OU_ID
    AND S_CONTACT.CON_ASST_PER_ID = Consultant.ROW_ID
    AND S_ORG_EXT.X_DIRECTOR_ID = ProgramDirector.ROW_ID (+)
    AND S_CONTACT.CREATED_BY = CallTaker.ROW_ID
    AND S_CONTACT.ROW_ID = a.PR_CON_ID (+)
    AND S_CONTACT.PR_PER_ADDR_ID = S_ADDR_PER.ROW_ID (+)
    AND S_CONTACT_TNTX.PAR_ROW_ID (+) = S_CONTACT.ROW_ID
    AND REFERRER.ROW_ID(+) = S_CONTACT_TNTX.REFERRED_BY_ID
    AND a.PROD_ID = S_PROD_INT.ROW_ID (+)
    AND O.CONTACT_ID (+) = S_CONTACT.ROW_ID
    AND a.STATUS_CD (+) = 'Active'
    AND a.TYPE_CD (+) ='Program'
    AND S_CONTACT.ROW_ID = a2.PR_CON_ID (+)
    AND a2.STATUS_CD (+) = 'Active'
    AND a2.TYPE_CD (+) = 'Lifecycle'
    AND a3.PR_CON_ID(+) = S_CONTACT.ROW_ID
    AND a3.STATUS_CD (+) = 'Active'
    AND a3.TYPE_CD (+) = 'HealthSheet'
    AND S_CONTACT.X_JC_ACNT_NUM = ct.CLIENT_NUMBER (+)
    --AND S_ORG_EXT.LOC NOT LIKE 'F%'
    AND S_ORG_EXT.ACCNT_TYPE_CD NOT IN 'Division'
    --AND S_ORG_EXT.Loc in (select to_char(centreid) from UPL_LIVE_CENTRES where LIVE = 'Y')
    AND (trunc(S_CONTACT.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) or trunc(S_CONTACT_X.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) OR (S_CONTACT_XM.X_CONSULTATION_DT = p_business_date) OR oxm2.CONTACT_ID IS NOT NULL)
    AND S_CONTACT.last_upd_by not in ('1-14WD')
    AND oxm2.CONTACT_ID (+) = o.CONTACT_ID
    AND S_ORG_EXT.LOC <> 'CW_846'
    AND (a.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a.pr_accnt_id is null)
    AND (a2.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a2.pr_accnt_id is null)
    AND (a3.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a3.pr_accnt_id is null));
    rollback;
    END;
    --------------------------------------------------------------------------------------------------

  • SQL Query with variable range

    Hi
      I want to give range to a user to enter in a variable through sql query . If there are 200 records , if user wants to display from 5-45 , 75-110 , 130-145. how it can be done through SQl Query
    Thanks
    Edited by: Matt on Aug 31, 2010 6:23 PM - modified title - please use a meaningful title in future

    Dear Saini,
    This query will allow you to choose the values only when you know them.
    SELECT T0.[DocEntry], T0.[ItemCode] FROM INV1 T0 WHERE T0.[LineNum] >[%0]   and T0.[LineNum] <[%1]
    If you run it in the query Generator in SAP Business One a little window will pop up and will ask you to choose the 2 variables.
    You can choose different variables every time you run it. At least you won't have to save many queries with different values.
    If you want 2 different groups, e.g. from 10 to 20 and from 30 to 40, then you can add another part in the where clause:
    SELECT T0.[LineNum], T0.[ItemCode], T0.[DocEntry] FROM INV1 T0 WHERE T0.[LineNum]  >= [%0] and  T0.[LineNum]  <= [%2] and T0.[LineNum]  >= [%4] or  T0.[LineNum]  <= [%6]
    Please, let me know if this query helps.
    Regards,
    Marcella Rivi
    SAP Business One Forums Team

  • Select SQL statement with variable syntax error

    Hi All,
    I am running a Web Application with a java bean to connect to a mysql database. i have compiled a test .java file whcih works using the same statement that has a problem in my web application. Taking the statement out of the Web App makes it work so it must be this stetment:
    String SQLStatement = "SELECT * FROM MASTER WHERE USERNAME LIKE '"+data+"' ";
    This works fine in testing a separate java file, but it does not compile when running ant build to compile the same line of code for my Web App.
    I have tried many possibilities of changing the syntax to no avail, its a puzzle!
    Many thanks for any swift reply.
    ChrisG

    prepare:
    copy:
    build:
    [javac] Compiling 1 source file to C:\jwsdp-1.3\garland\build\WEB-INF\classe
    s
    [javac] C:\jwsdp-1.3\garland\src\LogonBean.java:20: cannot resolve symbol
    [javac] symbol : variable data
    [javac] location: class logonApp.LogonBean
    [javac] String SQLState2 = "SELECT PASSWORD FROM MASTER WHERE PASSWORD L
    IKE '"+data+"' ";
    [javac]
    ^
    [javac] C:\jwsdp-1.3\garland\src\LogonBean.java:79: cannot resolve symbol
    [javac] symbol : variable SQLState1
    [javac] location: class logonApp.LogonBean
    [javac] rs = stmt.executeQuery(SQLState1);
    [javac] ^
    [javac] 2 errors
    Thats the compiler error, but it still works on a normal java file. ill try a prepared statement in the mean time.
    ChrisG

  • How to convert a sql statement with variable

    hello , please how can i convert the below with cast
    I need to be able to generate an explain plan, I believe I have to use cast.
    SELECT TO_NUMBER (OIL.UNIQUE_ID) REBALANCE_ORDER_ID,
    OIL.ORDER_QTY,
    OIL.ORDER_TYPE,
    OIL.ORDER_SIDE,
    OIL.POSITION_TYPE,
    OIL.AVAILABLE_QTY AVAILABLE_QUANTITY,
    OIL.ORDER_AMT GROSS_AMOUNT,
    OIL.NET_AMOUNT NET_AMOUNT,
    OIL.FEE_AMT FEE_AMOUNT,
    OIL.ACCRUED_INTEREST_AMT ACCRUED_INTEREST
    FROM TABLE (:B6) OIL

    >
    I need to be able to generate an explain plan, I believe I have to use cast.
    SELECT TO_NUMBER (OIL.UNIQUE_ID) REBALANCE_ORDER_ID,
    OIL.ORDER_QTY,
    OIL.ORDER_TYPE,
    OIL.ORDER_SIDE,
    OIL.POSITION_TYPE,
    OIL.AVAILABLE_QTY AVAILABLE_QUANTITY,
    OIL.ORDER_AMT GROSS_AMOUNT,
    OIL.NET_AMOUNT NET_AMOUNT,
    OIL.FEE_AMT FEE_AMOUNT,
    OIL.ACCRUED_INTEREST_AMT ACCRUED_INTEREST
    FROM TABLE (:B6) OIL
    >
    You are correct - cast the bind as the proper type. I have a SQL type named emp_table_type so this works
    explain plan for select * from table(cast (:e1 as emp_table_type))The types involved are
    CREATE OR REPLACE TYPE SCOTT.emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    CREATE OR REPLACE TYPE SCOTT.emp_table_type as table of emp_scalar_type
    /

  • PLSQL-generated SQL report with variable number of columns

    I created an app to track college football bowl picks:
    http://apex.oracle.com/pls/otn/f?p=21723
    The main report region includes columns for the various games as well as a column for each participant. In order not to hard code the number of participants, I used PLSQL to generate the SQL so that new columns could be added on the fly.
    However, whenever I add a new user I get this result -
    report error:
    ORA-01403: no data found
    If I copy and paste the PLSQL into a new report region and then delete the old one, however, all is well.
    Is there something I can do to overcome this?
    Thanks.
    Bill

    Roberto
    <br><br>
    Here are the tables:
    <br><br>
    BOWL_GAMES<br>
    ID     NUMBER<br>
    NAME     VARCHAR2(30)<br>
    FAV     VARCHAR2(20)<br>
    DOG     VARCHAR2(20)<br>
    BDATE     DATE<br>
    LINE     NUMBER(3,1)<br>
    FAV_SCORE     NUMBER(4,0)<br>
    DOG_SCORE     NUMBER(4,0)<br>
    <br>
    BOWL_USERS<br>
    ID     NUMBER<br>
    USERNAME     VARCHAR2(20)<br>
    PW     VARCHAR2(20)<br>
    NAME     VARCHAR2(20)<br>
    EMAIL     VARCHAR2(50)<br>
    <br>
    BOWL_PICKS<br>
    ID     NUMBER(5,0)<br>
    USERID     NUMBER(10,0)<br>
    GAMEID     NUMBER(10,0)<br>
    PICK     NUMBER(1,0)<br>
    <br>
    <br>
    Below is my PLSQL. Feel free to try out the app. Thanks.
    <br><br>
    Bill<br><br>
    declare<br>
    p_sql varchar2(32767);<br>
    cursor c1 is select * from bowl_users order by id;<br>
    begin<br>
    p_sql := q'! select to_char(b.bdate, 'Mon FMdd') "Date", b.name, '< a href="javascript$pickEm(''' || b.fav || ''')">' || b.fav || '</ a> -' || b.line || ' < a href="javascript$pickEm(''' || b.dog || ''')">' || b.dog || '</ a>' "Line" !';<br>
    for a1 in c1 loop<br>
    p_sql := p_sql || q'! , bowl_strike(b.id, !' || a1.id || q'! , 0) || (select decode(p.pick, 0, substr(b.dog,1,4), 1, substr(b.fav,1,4), 'No pick') from bowl_picks p where p.userid = !' || a1.id || q'! and p.gameid = b.id) || bowl_strike(b.id, !' || a1.id || q'! , 1) "!' || upper(a1.name) || q'!" !';<br>
    end loop;<br>
    p_sql := p_sql || q'! , bowl_score(b.id) "SCORE" from bowl_games b order by b.bdate !';<br>
    return replace(p_sql,'$',':');<br>
    end;
    <br><br>
    Message was edited by:
    [email protected]

  • SQL query with Bind variable with slower execution plan

    I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
    1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
    3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
    4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
    (Cost=2 Card=135 Bytes=6480)
    Statistics
    0 recursive calls
    18 db block gets
    15558 consistent gets
    47 physical reads
    9896 redo size
    423 bytes sent via SQL*Net to client
    1095 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
    2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
    3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
    4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
    0 recursive calls
    12 db block gets
    3003199 consistent gets
    54 physical reads
    9448 redo size
    423 bytes sent via SQL*Net to client
    1258 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
    Regards
    Ivan

    Many thanks for your reply.
    I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
    for table I use:-
    begin
    dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
    end;
    for index I use:-
    begin
    dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
    end;
    Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
    regards
    Ivan

  • Sql Loader with TSN environment variable.

    Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???

    952189 wrote:
    Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???
    >Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???
    if sqlldr is run on DB Server system, then no tnsnames.ora file is required.

  • How to create sql query for item master with operator LIKE with variables?

    hi all,
    How to create sql query for item master with
    operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
    Jeyakanthan

    Hi Jeyakanthan,
    here is an example (put the like statement into the where field)
    SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
    The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
    Regards Steffen

  • Transformation with PL/SQL Procedure

    Hi,
    I want to do the following transformation with the OWB.
    Table1 -> Transformation (Procdure) -> Table2
    The procedure should take the table structure of Table1 as input. The procedure sould process the data inside it.
    It should return the table structure of Table2 as output, so that Table2 can get populated with the transformed data.
    Can any of you please let me know how the above can be achieved efficiently with OWB (without the use of Table Functions) ?
    I am working with OWB10G Release 2.
    Thanks
    Anirban

    LS,
    Since the transformations are complex, using a temporary table does not simplify the mapping in OWB. A table function does keep the mapping in OWB simple and keeping maintenance simpler by keeping it out of OWB and into a tablefunction.
    The "walkthrough" of 'gladnn' in this post should give you a good start:
    Table Function
    Regards,
    André

  • Error in Looping with variable

    Dear All,
    Please help me. i want to loop of record. i have two scheme. First, i make without variable and not error. Second, i make with variable and error occurs. as below my syntax:
    First:
    declare
    x varchar(50);
    begin
    --x:='select dummy from dual';
    for c1 in (select dummy from dual) loop
    dbms_output.put_line(c1.dummy);
    end loop;
    end;
    result:
    X
    Second:
    declare
    x varchar(50);
    begin
    x:='select dummy from dual';
    for c1 in (x) loop
    dbms_output.put_line(c1.dummy);
    end loop;
    end;
    result:
    Encountered the symbol 'LOOP' when expecting one...

    Billy  Verreynne  wrote:
    Why? For what purpose?
    A cursor fetch loop is not the ideal processing structure.
    It is slow. It requires data to travel from the buffer cache of the database into PL/SQL variables (in the PGA). It requires context switching between the PL/SQL and SQL engines.
    It does not scale. More rows means more data to travel that path from the SQL engine to the PL/SQL engine. More loop iterations in PL/SQL. If a single loop iteration (for processing a row) is 1ms, then a 100,000 rows will take a 100 seconds. 200,000 rows 200 seconds. Etc. This clearly does not scale with an increase in data volume.
    Also keep in mind that DBMS_OUTPUT does not write to screen or display anything. It is incapable of accessing a client device as it executes inside a server process. So each call to DBMS_OUTPUT stores that line of text in very expensive server memory. When the database call is done, the client (e.g. TOAD or SQL*Plus) can read those lines from the database and the client can display it.
    So if your loop is for a 1000 rows, it means writing a 1000 lines of text into very expensive server memory - and then expecting the client to read that afterwards and display it. Why? This is not a standard client-server method. It also does not scale. It can actually crash the server when this method is abused.
    The standard method would be to create a SQL cursor using PL/SQL code, and then return a reference handle (pointer) to the client. This allows the client the ability to fetch data directly from the cursor - in an optimal way that does not consume expensive server memory.I have to say it: I sincerely appreciate you taking the time to write this whenever it needs to be written rather than just giving up and letting people stumble along with bad design - it must take a lot of mental stamina to keep doing it. One day it will sink into my head also :-)

  • Script fails when passing values from pl/sql to unix variable

    Script fails when passing values from pl/sql to unix variable
    Dear All,
    I am Automating STATSPACK reporting by modifying the sprepins.sql script.
    Using DBMS_JOB I take the snap of the database and at the end of the day the cron job creates the statspack report and emails it to me.
    I am storing the snapshot ids in the database and when running the report picking up the recent ids(begin snap and end snap).
    From the sprepins.sql script
    variable bid number;
    variable eid number;
    begin
    select begin_snap into :bid from db_snap;
    select end_snap into :eid from db_snap;
    end;
    This fails with the following error:
    DB Name DB Id Instance Inst Num Release Cluster Host
    RDMDEVL 3576140228 RDMDEVL 1 9.2.0.4.0 NO ibm-rdm
    :ela := ;
    ERROR at line 4:
    ORA-06550: line 4, column 17:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( - + case mod new not null &lt;an identifier&gt;
    &lt;a double-quoted delimited-identifier&gt; &lt;a bind variable&gt; avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    &lt;a string literal with character set specification&gt;
    &lt;a number&gt; &lt;a single-quoted SQL string&gt; pipe
    The symbol "null" was substituted for ";" to continue.
    ORA-06550: line 6, column 16:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( - + case mod new not null &lt;an identifier&gt;
    &lt;a double-quoted delimited-identifier&gt; &lt;a bind variable&gt; avg
    count current exists max min prior sql stddev su
    But when I change the select statements below the report runs successfully.
    variable bid number;
    variable eid number;
    begin
    select '46' into :bid from db_snap;
    select '47' into :eid from db_snap;
    end;
    Even changing the select statements to:
    select TO_CHAR(begin_snap) into :bid from db_snap;
    select TO_CHAR(end_snap) into :eid from db_snap;
    Does not help.
    Please Help.
    TIA,
    Nischal

    Hi,
    could it be the begin_ and end_ Colums of your query?
    Seems SQL*PLUS hs parsing problems?
    try to fetch another column from that table
    and see if the error raises again.
    Karl

  • SQL query with JSP and WML-parameters

    Hey,
    Could you help me?
    I'm trying to do the following. WML deck card 1 send parameter to same WML deck's card help. I try to read the parameter with JSP in card help by putting the parameter to SQL query, but it doesn't work. I can read the parameter with WML in card help. I can also print the value of the parameter with JSP if I generate WML with JSP.
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi' value='$(valittukurssi)'/>");
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    /'parameter read with JSP by generating WML with JSP*/
    out.println("<p>$valittukurssi</p>");
    /* SQL query with JSP */
    ResultSet uudettulokset = uusilause.executeQuery("select * from kurssi where lyhenne='$valittukurssi'");
    Thanks,
    Rampe

    You're problem is easy to fix. You're confusing WML variables with JSP variables. See below:
    >
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi'
    value='$(valittukurssi)'/>");
    Above you set a var that will work on the phone, not in JSP.
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    Yes the above does display the parameter, because it is a client side WML var, but you cannot use this variable in the JSP code (that's why your SWL fails).
    /'parameter read with JSP by generating WML with
    JSP*/
    out.println("<p>$valittukurssi</p>");Here's you're problem, the above line is EXACTLY the same as the one before it. When the container parses through this JSP code it translates the above line to:
    <p>$valittukurssi</p> on the WML page and the CLIENT uses it's local variable to display it.
    What you need and want is to have a variable that can be used in JSP code and output to your WML page. Here's how it's done:
    out.println("<go href='#helpcard'>");
    String some_name = "valittukurssi";
    out.println("<setvar name='"+some_name+"'
    value='$("+some_name+")'/>");
    //note that you may have to escape the ( and ) with a \
    //so we displayed the variable above into the WML page, now we can use it in the SQL query:
    /* SQL query with JSP */
    ResultSet uudettulokset =
    uusilause.executeQuery("select * from kurssi where
    lyhenne='"+some_name+"'");//the end of the command is: " ' " ) ;
    Frank Krul
    Got Node?

  • SQL Injection and variable substitutions

    Hello helpful forum, I'm trying to understand what really goes on "behind" the scenes
    with the variable substitutions in order to protect from sql injections.
    I'm using apex 3.0.0.00.20
    The trickiest component seems to be a Report of type "pl/sql returning sql", since
    multiple dynamic sql interpretations are done there.
    consider the following innocent looking disaster:
    DECLARE
    l_out VARCHAR2(2000);
    BEGIN
    l_out := 'select * from test_injection t where t.name like ''%' || :NAME || '%''';
    RETURN l_out;
    END;
    if NAME is a single quote the report will return:
    failed to parse SQL query: ORA-00911: invalid character
    which hints to the fact that NAME is not escaped, and you are in fact able to access db functions
    as in: '||lower('S')||'
    I also tried to put there a function that runs in a autonomous transaction to log its calls, and
    I see that it's called five times for each request.
    consider now the similar solution (notice the two single quotes):
    DECLARE
    l_out VARCHAR2(2000);
    BEGIN
    l_out := 'select * from test_injection t where t.name like ''%'' || :NAME || ''%''';
    RETURN l_out;
    END;
    with this second example nothing of the above is possible.
    So my theory (please confirm it or refute it) is that there is a first variable substitution done
    at the pl/sql level (and in the second case :NAME is just a string so nothing is substituted).
    Then the dynamic sql is executed and it returns the following string:
    select * from test_injection t where t.name like '%' || :NAME || '%'
    now another substitution is done (at an "APEX" level) and then query is finally executed to return
    the rows to the report.
    The tricky point seems to be that the first substitution doesn't escape the variable (hence the error
    with the single quote), while the second substitution does.
    Please let me know if this makes sense and what are the proper guidelines to avoid sql injection with
    the different kinds of reports and components (SQL, pl/sql returning sql, processes, ...)
    Thanks

    Giovanni,
    You should build report regions like this using the second method so that all bind variables (colon followed by name) appear in the resultant varchar2 variable, l_out in your example, which will then be parsed as the report query. This addresses not only the SQL injection problem but the shared-pool friendliness problem.
    Scott

Maybe you are looking for

  • Acrobat Reader DC  one source of pdf attached files

    I have a MacBook Pro and found that since updating to Acrobat Reader DC there is one source of pdf attached files that do not open (I just get a black screen). I do not have this problem with my iPad nor with an iMac also running the same reader.  I

  • I tunesis in need of some serious workmanship

    Just bought the ipod touch 16G, and I love it. A serious piece of good engineering given the constraints. I can't say the same about Itunes , especially when you consider that it is in it's 7th edition (who knows how many actual versions?). Itunes pr

  • HTTP - Xi - RFC : Handle rfc return in bpm

    Hi, I have configured receiver RFC and calling synchronous BAPI works perfectly. Now the response message in RFC is containing results in return table and even if it's a error message the xi message is in ok status (sxmb_moni). My request is how can

  • Apostrophe error for sql

    hi all, i keep having this syntax error with sql statement with words like I'm, she's..etc. any words with apostrophe's is misunderstood by sql. have searched for various solutions and tried this but it still doesnt work: String name=request.getParam

  • Why is my 6.0 fire fox crashing

    my fire fox keeps freezing and set a few reports plz help