Passing a Date variable to SQL

Hi,
I am trying to pass in a Date variable into SQL query, but I am getting this error:
"inconsistent datatypes: expected DATE got NUMBER"
and my code looks like this. I would appreciate any help on how I need to create the Date variable that SQL would accept it.
THANKS A LOT!
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
String txt = "01/01/1990";
java.util.Date startYear2 = (java.util.Date) formatter.parse(txt, new ParsePosition(0));
java.sql.Date startYear = new java.sql.Date(startYear2.getTime());
String txt2 = "12/31/1990";
java.util.Date endYear2 = (java.util.Date) formatter.parse(txt2, new ParsePosition(0));
java.sql.Date endYear = new java.sql.Date(endYear2.getTime());
String scoredGoalsQuery = "SELECT count(name) from player_goal_rel where name = '" + pName + "' and pdate BETWEEN "+ startYear +" and "+ endYear;
ResultSet scoredGoalsResult = stmt.executeQuery(scoredGoalsQuery);

You should be using prepared statements.
String scoredGoalsQuery = "SELECT count(name) from player_goal_rel where name = ? and pdate BETWEEN ? and ?":
PreparedStatement pstmt = connection.prepareStatement(scoredGoalsQuery);
pstmt.setString(1, pName);
pstmt.setDate(2, startYear);
pstmt.setDate(3, endYear);
ResultSet scoredGoalsResult = pstmt.executeQuery();

Similar Messages

  • Passing value of variable in SQL

    Hi,
    How to pass the value of variable from a shell script in the oracle sql command...,
    for eg :
    say echo $name returns 'test1'..
    then, how i can pass this 'test1' for a tablespace_name column for a select query in dba_data_files view....
    Also, can this be performed in a ddl statement?,
    Pls help..thanks!

    can this be performed in a ddl statement?It can be done with any sql statement :
    $ cat test.sh
    sqlplus -s test/test << EOF
    create table $1 (a number, b varchar2(20));
    exit
    EOF
    $ ./test.sh foo
    Table created.
    $ sqlplus test/test
    SQL*Plus: Release 10.2.0.2.0 - Production on Mon Jun 25 15:26:46 2007
    Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> desc foo
    Name                                      Null?    Type
    A                                                  NUMBER
    B                                                  VARCHAR2(20)
    SQL>

  • Passing table data to pl sql procedure oaf

    Hi All,
    I have a requirement where i have to pass table data to plsql procedure.
    In the first page i select the REQUISITION and click on RETURN button and it will take me to the next page.
    and in the Next page i will click on APPLY button.
    When i click on APPLY, it will call the procedure and will give input to the procedure whatever has been selected when i have selected requisition.
    Please help. Please tell me the approach how to get this task done. A sample code will work.
    Hope the requirement is clear.
    Thanks in Advance.

    Hi Chinmay,
    Refer below code for Your Requirement.
    //Code For Quering Data
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
    String Query = "SELECT organization_id FROM hr_operating_units WHERE organization_id = fnd_global.org_id";
    PreparedStatement stmt = conn.prepareStatement(Query);
    resultset=stmt.executeQuery();
    while (resultset.next())
    orgId = (String)resultset.getString("ORGANIZATION_ID").toString();
    conn.commit();
    catch(Exception e)
    e.printStackTrace();
    //Code for Pass Resulted column to Procedure Input for delete Particular Record
    Execute parameterized PL SQL procedure from OAF page
    Let us try to call PL/SQL package from OAF page. We will try to remove selected line from Database.
    Package Spec
    CREATE OR REPLACE PACKAGE APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2);
    END genpack_pkg;
    Package Body
    CREATE OR REPLACE PACKAGE BODY APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2)
    AS
    BEGIN
    DELETE FROM pklist_roll_details_temp
    WHERE roll_line_id = orgId;
    COMMIT;
    END roll_delete_proc;
    END genpack_pkg;
    //in Controller PFR
    import java.sql.CallableStatement;
    if (pageContext.getParameter("ActionsButton") != null)
    String val = pageContext.getParameter("ActionsChoice");
    if ("DELLN".equals(val))
    CallableStatement cstmt = null;
    for (OAViewRowImpl row = (OAViewRowImpl)tempvo.first(); row != null; row = (OAViewRowImpl)tempvo.next()) {
    if ((row.getAttribute("Selectflag") == null) ||
    (!row.getAttribute("Selectflag").toString().equals("Y"))) continue;
    try {
    int rollid = Integer.parseInt((String)row.getAttribute("orgId"));
    Connection conn = am.getOADBTransaction().getJdbcConnection();
    if (rollid == 1)
    temphm.put(row.getAttribute("orgId").toString(), row.getAttribute("PoNumber").orgId());
    tempvo.removeCurrentRow();
    else
    try
    StringBuilder sb = new StringBuilder();
    sb.append(rollid);
    String strI = sb.toString();
    System.out.println("Inside else in delete");
    cstmt = conn.prepareCall("{call GENPACK_PKG.tpc_roll_delete_proc(?)}");
    cstmt.setString(1, strI);
    System.out.println("Oracle Callable Statment Execution Init for Delete");
    cstmt.execute();
    catch (SQLException e) {
    throw new OAException(e.toString(), (byte)0);
    }tempvo.removeCurrentRow();
    catch (OAException e) {
    throw new OAException("No row selected", (byte)3);
    Thanks,
    Dilip

  • How to bind DATE variables in SQL*Plus

    I have a stored procedure in a package that has a DATE OUT parameter
    myPackage.myProcedure( outDate OUT DATE )
    I am trying to test this from SQL*Plus
    How do I specify a Bind variable for the outDate? The VARIABLE command does not allow DATE types?
    If this was a CHAR type I could have done
    VARIABLE myChar CHAR
    BEGIN
    myPackage.myProcedure( :myChar )
    END;
    PRINT myChar
    How do I do this with DATE data types instead? I am using Oracle 8.1.7.

    you should use VARCHR2 type with the minimum length that can store a value defined by your NLS_DATE_FORMAT
    string. The returned date will be converted to a VARCAHR2 type and the size and format will depend on
    your NLS_DATE_FORMAT setting.
    =============================================================================
    SQL> variable dt VARCHAR2(20)
    SQL> create or replace procedure ret_date(dt OUT DATE) is
    2 begin
    3 dt := SYSDATE ;
    4 end ;
    5 /
    Procedure created.
    SQL> exec ret_date(:dt) ;
    PL/SQL procedure successfully completed.
    SQL> print dt
    DT
    13-OCT-02
    SQL> select sysdate from dual ;
    SYSDATE
    13-OCT-02
    SQL> alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ;
    Session altered.
    SQL> exec ret_date(:dt) ;
    PL/SQL procedure successfully completed.
    SQL> print dt
    DT
    13-OCT-2002 10:43:23
    SQL>
    ================================================================

  • Passing Session State Variables to SQL query

    Hi,
    I am using 3 pages in my application build by APEX 3.1.2. Login Page, Report Page and Form Page.
    I am using LDAP authentication for Login Page and I want the user session information to be feeded to the filter query
    being used to display data on Report Page. Is there any way to do that. I know
    there is one variable %LDAP_USER% which is using the userid given on login
    page. But I dont know how to use APEX session variables to filter query. Need
    assistance on that stuff.
    Thanks,
    Gaurav

    Hi Gaurav,
    Session "variables" (global items, application items and page items) can be accessed using v('ITEM_NAME') (for strings) or nv('ITEM_NAME') (for numbers) within sql queries/procedures/triggers etc.
    If you look at the Substitution Strings section here: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/index.htm#S you'll find more information about this and a list of items that you can use that are set by Apex itself.
    Andy

  • Passing shell script variable to sql file by reference (bind variable)

    Hi All,
    I need to import around 50 files every 15 minutes into my target table.
    I am using shell script and call procedure to do transform.
    I used crontab to do this automate task.
    Here is my shell script and sql file:
    shell script:
    #!/bin/sh
    export ORACLE_HOME=/u01/app/oracle/product/9.2.0.4.0
    export PATH=$ORACLE_HOME/bin
    find /path_rawfile/rawfile -iname raw\*.in > myfile.lst
    nfile=1
    while [ true ]
    do
    read iFile #read a line
    if [ $? -ne 0 ] #Break if EOF
    then
    break
    fi
    #$PATH/sqlplus -s /NOLOG @load_raw.sql $iFile
    #/bin/mv -f $iFile /path_rawfile/rawfile/done/
    done < myfile.lst
    sql file:
    connect test/test@evn1
    set serveroutput on
    variable filename varchar2(50)
    begin
    :filename := '&1';
    exec my_tranform(:filename);
    dbms_output.put_line(:filename);
    end;
    exit;
    Even I used bind variable pass to procedure my_transform...
    But when i query in sys.v_$sqlarea, the :filename:='&1' still hard parse to sqlarea.
    One filename one statement and keep increasing ..
    Could everyone help me to change it to bind varialbe(soft parse)?
    I would like to incresae my database performance.
    Thanks in advance.
    Cheer
    Message was edited by:
    lux

    It is the procedure.
    It's my fault.
    Here is my SQL file again:
    conn test/test@evn1
    variable filename varchar2(500);
    exec :filename:='&1';
    exec my_transform(:filename);
    exit;
    I call this sql file from shell script and call in loop due to i need to load all file one time.
    Once i use <<EOF it raise error that's why when I deleted it.
    Anyway, what I need to do here is to use bind variable (soft parse).
    Since I need to load around 50 files every 15 minutes.
    exec :filename:='&1'; this statmet have found hard parse in v_$sqlarea.
    I would like to change this to bind varialbe.
    Thanks again for your help.

  • Pass unicode data in SQL Server 2008 stored procedure parameter

    Hi,
    I want to pass unicode data in a SQL stored procedure. But I am not sure that how to append N with NVarchar datatype.
    For example I Create a table LocalizationTest and wants to insert a few records.
    Create table LocalizationTest
        Field1 NVarchar(255)
    INSERT INTO LocalizationTest
    VALUES(N'123 Illini Dr, 東皮奧里亞, 8989')
    the above given statement works.
    To explain it more , script A works but script B does not work.
    DECLARE @X NVARCHAR(255)
    [A]
    SET @X=N '123 Illini Dr, 東皮奧里亞, 8989'
    INSERT INTO LocalizationTest
    VALUES(@X)
    [B]
    SET @X= '123 Illini Dr, 東皮奧里亞, 8989'
    INSERT INTO LocalizationTest
    VALUES(@X)
    What is the correct way to execute script B because @X will be passed in a SQL Stored Procedure?
    Thanks
    Sharma M.

    If you do not pass the value as a Unicode value there is nothing left of the Unicode characters but question marks. Once this has happened, AFAIK there is no way to undo it (other than resetting the value as Unicode characters again).
    Affirmative.
    Demo - This is what happens if you convert UNICODE (nvarchar) to varchar with implicit conversion (try to force 2 bytes into one byte).
    3F hex is '?'.
    CREATE TABLE #LocalizationTest (Field1 VARCHAR(255))
    INSERT INTO #LocalizationTest
    VALUES(N'123 Illini Dr, 東皮奧里亞, 8989')
    DECLARE @X NVARCHAR(255), @dSQL NVARCHAR(MAX)
    SET @X=N'123 Illini Dr, 東皮奧里亞, 8989'
    INSERT INTO #LocalizationTest VALUES(CONVERT(NVARCHAR(255),@X))
    SET @dSQL = N'INSERT INTO #LocalizationTest VALUES(N'''+@X+''')'
    PRINT @dSQL
    EXEC sp_ExecuteSQL @dSQL
    SELECT *, Field1Bin=convert(binary(30), Field1) FROM #LocalizationTest
    DROP TABLE #LocalizationTest
    123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
    123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
    123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Passing Global Variable in Sql Object

    Hi
    How can i pass my global variable into SQL object? I tried to pass it but then I tried to update the schema it giving me the error at varble
    Please advise me

    The Update schema is used only to get the structure for the Output.
    Once you have a valid structure and the SQL Parses without any variables use the syntax for applying variables as in any Script within DI.
    $GV_MyVar enclosed within square brackets will be replaced by Value of the variable.
    $GV_MyVar enclosed within curly brackets will be replaced by Value of the variable enclosed in single quotes.
    When the job runs, the variables will be replaced with values OR values with quotes. It is at this time, the SQL send to the database is validated for syntax.
    Therefore, you will not know the validity of your SQL with Global Variables until you run the job.
    Hope this helps!
    Thanks & Regards
    Tiji
    Edited by: Tiji Mathew on May 8, 2009 3:40 PM
    The actual syntax was being posted as a link. edited to make the text descriptive.

  • Passing the sh variable value to input of  to Pl/SQL Procedure

    Hi All,
    My doubt is how can I pass the sh variable (.i.e file name stored in sh variable called($F)) as a input of below mention procedure (YODEL_XL_INS_SDG_COMMER_PROD)
    for F in *.dat; do
    echo $F
    #sqlldr apps/apps control=$CONTROL data=$F
    # Below Part is used for Add the file name into table
    cat $CONTROL| sed "s/:FILE/$F/g" > $F.ctl
    sqlldr apps/apps control=$F.ctl log=$F.log bad=$F.bad discard=$DISCARD data=$F
    sqlplus -s apps/apps << EOF
    spool Yodel_xl_om_inven_items_pkg.txt
    set serveroutput on;
    DECLARE
    X_Error_Code VARCHAR2(1000);
    X_Error_Message VARCHAR2(1000);
    X_Status VARCHAR2(1000);
    BEGIN
         YODEL_XL_INS_SDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    END;
    SHOW ERRORS;
    spool off;
    exit
    EOFDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    If i'm passing directly then getting below error.
    YODEL_XL_INS_SDG_COMMER_PROD(SDG_Testing_produsts3.dat,'SDG',X_Status,X_Error_Code,X_Error_Message);
    ERROR at line 8:
    ORA-06550: line 8, column 66:
    PLS-00201: identifier 'SDG_Testing_produsts3.dat' must be declared
    ORA-06550: line 8, column 2:
    PL/SQL: Statement ignored
    No errors.
    Could you please help me to resolve this.
    Edited by: user9077611 on 30-Aug-2012 10:11

    user9077611 wrote:
    Hi All,
    My doubt is how can I pass the sh variable (.i.e file name stored in sh variable called($F)) as a input of below mention procedure (YODEL_XL_INS_SDG_COMMER_PROD)
    for F in *.dat; do
    echo $F
    #sqlldr apps/apps control=$CONTROL data=$F
    # Below Part is used for Add the file name into table
    cat $CONTROL| sed "s/:FILE/$F/g" > $F.ctl
    sqlldr apps/apps control=$F.ctl log=$F.log bad=$F.bad discard=$DISCARD data=$F
    sqlplus -s apps/apps << EOF
    spool Yodel_xl_om_inven_items_pkg.txt
    set serveroutput on;
    DECLARE
    X_Error_Code VARCHAR2(1000);
    X_Error_Message VARCHAR2(1000);
    X_Status VARCHAR2(1000);
    BEGIN
         YODEL_XL_INS_SDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    END;
    SHOW ERRORS;
    spool off;
    exit
    EOFDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    If i'm passing directly then getting below error.
    YODEL_XL_INS_SDG_COMMER_PROD(SDG_Testing_produsts3.dat,'SDG',X_Status,X_Error_Code,X_Error_Message);
    ERROR at line 8:
    ORA-06550: line 8, column 66:
    PLS-00201: identifier 'SDG_Testing_produsts3.dat' must be declared
    ORA-06550: line 8, column 2:
    PL/SQL: Statement ignored
    No errors.
    Could you please help me to resolve this.
    Edited by: user9077611 on 30-Aug-2012 10:11You know that strings should be enclosed in single quote marks.
    Right?

  • How do I Pass a parameter to a SQL Component Task where the source SQL statement is also a variable

    Hi,
    I have been tasked with making a complex package more generic.
    To achieve this I need to pass a parameter to a SQL Component Task where the source SQL statement is also a variable.
    So to help articulate my question further I have create a package and database as follows; -
    USE [KWPlay]
    GO
    /****** Object: Table [dbo].[tblTest] Script Date: 05/14/2014 17:08:02 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[tblTest](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [Description] [nvarchar](50) NULL,
    CONSTRAINT [PK_tblTest] PRIMARY KEY CLUSTERED
    [ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    I populated this table with a single record.
    I unit tested the SQL within SSMS as follows;
    SELECT * FROM dbo.tblTest
    Result; -
    ID           
    Description
    1             
    Happy
    DECLARE @myParam NVARCHAR(100)
    SET @myParam = 'Sad'
    UPDATE dbo.tblTest SET [Description] = @myParam FROM dbo.tblTest WHERE ID = 1
    SELECT * FROM dbo.tblTest
    Result; -
    ID   
    Description
    1    
    Sad
    Within the package I created two variables as follows; -
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = @myParam FROM dbo.tblTest WHERE ID = 1
    Name: strStatus
    Scope: Package
    Data Type: String
    Value: Happy
    I then created a single ‘Execute SQL Task’ component within the control flow as follows; -
    However when I run the above package I get the following error; -
    SSIS package "Package.dtsx" starting.
    Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "UPDATE dbo.tblTest SET [Description] = @myParam FR..." failed with the following error:
    "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Task failed: Execute SQL Task
    Warning: 0x80019002 at Package: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. 
    The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the
    errors.
    SSIS package "Package.dtsx" finished: Failure.
    I also tried; - 
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = ? FROM dbo.tblTest WHERE ID = 1
    However I received the error; - 
    SSIS package "Package.dtsx" starting.
    Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "UPDATE dbo.tblTest SET [Description] = ? FROM dbo...." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with
    the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Task failed: Execute SQL Task
    Warning: 0x80019002 at Package: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches
    the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
    SSIS package "Package.dtsx" finished: Failure.
    Kind Regards,
    Kieran.
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Tried; - 
    Name: strSQL
    Scope: Package
    Data Type: String
    Value: UPDATE dbo.tblTest SET [Description] = ? FROM dbo.tblTest WHERE ID = 1
    and; - 
    Result; - 
    SSIS package "Package.dtsx" starting.
    SSIS package "Package.dtsx" finished: Success.
    Therefore the answer was to put the parameter number rather than the parameter name under the parameter mapping tab-> parameter name column. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

  • Data services with SQL Server 2008 and Invalid time format variable

    Hi all
    Recently we have switched from DI on SQL Server 2005, to DS(Date Services) on SQL Server 2008. However I have faced an odd error on the query that I was running successfully in DI.
    I validate my query output using a validation object to fill either Target table (if it passes), or the Target_Fail table (if it fails). Before sending data to the Target_Fail table, I map the columns using a query to the Target_Fail table. As I have a column called 'ETL_Load_Date' in that table, which I should fill it with a global variable called 'Load_Date'. I have set this global variable in the script at the very first beginning of the job. It is a data variable type:
    $Load_Date = to_char(sysdate(),'YYYY.MM.DD');
    When I assign this global variable to a datetime data type cloumn in my table and run the job using Data Services, I get this error:
    error message for operation <SQLExecute>: <[Microsoft][ODBC SQL Server Driver]Invalid time format>.
    However I didn't have this problem when I was running my job on the SQL Server 2005 using Data Integrator. The strange thing is that, when I debug this job, it runs completely successfully!!
    Could you please help me to fix this problem?
    Thanks for your help in advance.

    Thanks for your reply.
    The ETL_Date is a datetime column and the global variable is date data type. I have to use the to_char() function to be able to get just the date part of the current system datetime. Earlier I had tried date_part function but it returns int, which didn't work for me.
    I found what the issue was. I don't know why there were some little squares next to the name of the global variable which I had mapped to the ETL_Date in the query object!!! The format and everything was OK, as I had the same mapping in other tables that had worked successfully.
    When I deleted the column in the query object and added it again, my problem solved.

  • SQL: Having problems passing a date value to dynamic SQL

    SQL Version 2008 (not R2)
    Problem:  1)  I'm getting the following error message when trying to run the sql code below.
    SQL "Messages" Returned when running code:
    Msg 206, Level 16,
    State 2, Procedure uspxc_WAWP_10_Get_VPData, Line 0
    Operand type clash: int is incompatible with date
    Loaded VP DATA for Month: 20121201
    Problem Code Line: 
    SET @dynamicSQL = 'EXEC ' + @StoredProcedureName + ' ' + @DEVModeYN + ', ' + CAST(@WIPMonth as varchar);
    Any help would be greatly appreciated.  I've spent several hours trying to get around this error.
    Full Code:
    ALTER PROCEDURE [dbo].[uspxi_XIUD_98_DataConversionGET_VP_WIPJobHistory] (@DEVModeYN nchar(1) = 'D', @WIPMonth Date)
    AS
    BEGIN 
     SET NOCOUNT ON;
     DECLARE @returnCode AS INT ,
       @dynamicSQL AS VARCHAR(8000),
       @msg as varchar(60),
       @DEVModeYN nchar(1) = 'D',
       @WIPMonth date = '20121201',
       @StoredProcedureName AS VARCHAR(60)
     SET @returnCode = 0
     SET @StoredProcedureName = 'uspxc_WAWP_10_Get_VPData'
    -- Check to see if @StoredProcedureName exists in the database.
    IF EXISTS(SELECT name FROM sys.procedures WHERE name = @StoredProcedureName)
     BEGIN 
      -- RUN SP to Import VP Data for each WIPMonth parameter value
      SET @dynamicSQL = 'EXEC ' + @StoredProcedureName + ' ' + @DEVModeYN + ', ' + CAST(@WIPMonth as varchar);
      SELECT @dynamicSQL;
      -- RUN stored procedure for WIP Month
      EXEC (@dynamicSQL);
      SET @returnCode = 0;
      SELECT @returnCode;
      SET @msg = 'Loaded VP DATA for Month: ' + @WIPMonth;
      PRINT @msg;
      GoTo SPEND
     END 
     ELSE
      SET @returnCode = 1;
      SET @msg = 'NO DATA IMPORTED for Month: ' + CAST(@WIPMonth as varchar(10))
      PRINT @msg
    SPEND:
    END
    Bob Sutor

    When you work with dynamic SQL, you should never build a full SQL string by concatenating values, because this is more difficult to get right and also has problems with SQL injection and efficient use of the SQL Server cache.
    So the correct way to do this in dynamic SQL would be:
    SET @dynamicSQL = 'EXEC ' + quotename(@StoredProcedureName)  '@DEVModeYN, @WIPMonth';
    EXEC sp_executesql @SQL, N'DEVModeYN nchar(1), @WIPMonth date',
                       @DEVModeYN, @WIPMonth
    A lot easier and cleaner! (Note that the variable @SQL must be declared as nvarchar.)
    ...however, in this particular case, this is still an overkill, and there is no need for dynamic SQL at all. EXEC accepts a variable for the procedure name, so:
    EXEC @StoredProcedureName @DEVModeYN, @WIPMonth
    ...but it does not stop there. You can make all these changes, but you will get the same error. To wit, you get the error on Line 0, which means that it is the call to the procedure that fails. Apparently, you are passing an integer value, when you were
    supposed to pass a date. Maybe you forgot to put the dates in quotes?
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How can I pass a Presentation Variable (Date) into a prompt

    Hello
    How can I pass a Presentation Variable (date) into a prompt? I seem to be able to do this successfully for a non-date value but have had no luck with a Date variable.
    Here's a simplistic version of what I'm trying to do:
    1. I have a Presentation Variable called startDate which is a Date that defaults to this SQL - SELECT "Reporting Dates"."Measure Date" FROM Trading WHERE "Reporting Dates"."Date Name" = 'Current'.
    2. I now want to pass this variable into a prompt with SQL like this: SELECT "Position Date"."Position Date" FROM Trading where "Position Date"."Position Date" = date'@{startDate}{2009-04-24}'
    I get this error: Datetime value @{startDate}{2009-04-24} from @{startDate}{2009-04-24} does not match the specified format.
    Now I can use the exact same syntax in a filter. For example, a simple Answers request where I pick Position Date with a filter saying "Position Date"."Position Date" = date'@{startDate}{2009-04-24}' works fine.
    What am I doing wrong?
    Thanks!

    Can you provide more information please?
    1. What is the format of the first date prompt, is it YYYY-MM-DD or?
    2. Which data type is Position Date."Position Date" in the physical layer, date or date time?
    3. What is the column formula in the first prompt?
    4. The first prompt is set to drop-down or?
    5. If you are using this SQL Results in the second prompt:
    SELECT "Position Date"."Position Date" FROM Trading where "Position Date"."Position Date" = date '@{startDate}{2009-04-24}'
    then @{startDate} must be in YYYY-MM-DD format to work properly, otherwise (for example):
    datetime value 01/01/2000 from 01/01/2000 does not match the specified format.
    This doesn't work for example:
    SELECT Times.time_id FROM "Normal model" where Times.time_id =date '01/01/2000'
    Regards
    Goran
    http://108obiee.blogspot.com

  • How do I enable Data Management if Passing an extra variable to PHP script?

    Im trying to use dynamic SQL tables on my PHP server so I need to pass the table name to the PHP script.  I don't understand why the Data Management system that sets up CRUD won't allow this extra parameter.  It says it can only have one input: item. I can get all records, but when I try to create, update, or delete I get an error.
    Or is there another way I can pass the tablename variable to the php file before I call any functions?
    Thanks!

    I use it but does not work for me.
    It does not integrates.
    You can tag on url value pairs onto your php function call such as:
    http://www.yourpath.php?tablename=tablenamesears
    You can then extract tablename, by using get in your php script:
    $tn = $_GET['tablename'];
    This $tn can be used anywhere in your php script as a dynamic value for table targeting.
    You can pass as many value pairs as you wish, every preceding pair must be in the form:
    http://www.yourpath.php?tablename=tablename&action=update&author=admin
    Hope it helps

  • In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String

    In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .

    Hi Srinath,
    The below blog might be useful
    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
    PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
    regards,
    Harish

Maybe you are looking for