execute sql task is not working

  • Hi all,

    I have execute sql task and I am passing two input parameters and the parametername is set to 0 and 1 and the connection type is OLE DB and I am passing the SQL statement as follows:

    SELECT DISTINCT ? FROM ?

    The Bypassprepare property is set to TRUE and as I need to capture the full result set into an object type variable I've the set the property Resultset to FULL RESULT SET.

    when I am executing the SQL TASK it is failing and giving the following error:

    [Execute SQL Task] Error: Executing the query "SELECT DISTINCT ? FROM ?" failed with the following error: "Must declare the table variable "@P2".". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

    If i am giving the sql statement property like below it is working fine

    SELECT DISTINCT EMAILID FROM TEST_EMAIL

    Please help me to resolve this issue. I thank in advance...

    Thanks,

  • Your problem is you are trying to pass the name of a table as a paramater, or as a variable. You can't use a variable in the FROM clause. What you are attempting to accomplish will actually require dynamic sql to accomplish.

  • Hi Lynn,

    Thank you very much. I resolved the issue by applying dynamic sql.

    Thanks once again and I appreciate for your help.

    Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply