2

I'm trying to use the logic for using SSIS

select top 2 * from table 

How can I replace 2 with variable name and make it customize?

Update

I tried using expression and i received the following error:

enter image description here

2

2 Answers 2

3

Assuming that the variable that contains the number of top rows is named @[User::TopCount]

Create a variable of type string (example: @[User::strQuery]), set its property EvaluateAsExpression to True. And assign the following expression:

"SELECT TOP " + (DT_WSTR,10)@[User::TopCount] + " * FROM table"

Inside the data flow task add an OLEDB Source and set the Access mode to SQL Command from variable and use @[User:strQuery variable as source.

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

2 Comments

@TirathSingh can you provide the expression used?
@TirathSingh check the following link: mssqltips.com/sqlservertip/4564/… follow the SSIS Expression for Variables section
2
declare @numrows int = 5

select top (@numrows) * from MyTable

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.