2

when writing my SQL command I specify ? to indicate that I want to use a passed in Parameter. However, for every ? I use, the package thinks it's a new parameter even though I want to use the same one.

enter image description here

6 ? = 6 new parameters though each parameter is the same. As seen on parameter 0 and 1

Is there a way that I can specify just one parameter?

Thanks

1
  • you can declare a variable, pass it a parameter and use it in the Where clause. take a look to my answer Commented Apr 5, 2017 at 18:10

3 Answers 3

1

You can achieve this by declaring a variable in you SQL Command and pass it a parameter then use this variable in the WHERE clause. like the following

DECLARE @str AS INT

SET @str = ?

SELECT        Column1
FROM            Table1
WHERE        (Column2= @str or Column3 = @str)

enter image description here

enter image description here

Other Workarounds

1)

Assuming you want to create the following query

Select * From Table1 Where [Column1] = ? Or [Column2] = ?
  1. Declare a variable (ex: User::strQuery)
  2. Store your parameter in a variable (ex: User::Value)
  3. Set the variable EvaluateAsExpression property to True
  4. Set the expression to the following:

    "Select * From Table1 Where [Column1] = " + @[User::Value] + " OR [Column2] = " + @[User::Value]
    
  5. In the OLEDB Source Set the source to SQL Command from variable and choose the variable @[User::strQuery]

2)

You can create a stored procedure or a table-valued function that take one parameter and use it as source

Sign up to request clarification or add additional context in comments.

1 Comment

I see, that was pretty simple to be fair. I am ashamed of my question. thanks
1

Could you declare a variable inside your SQL statement script that takes the value of the parameter via the ?, and then use the variable after that?

Comments

1

Create a stored procedure on SQL Server that takes one parameter and contains the correct query. Invoke the stored procedure with the one parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.