1

I want to use limit in mssql, which is TOP, parametrized. I hoped I can get top parametrized like that:

engine.execute( text("select top :t * from Orders), t=100)  

but I get: Statement(s) could not be prepared. (8180) (SQLExecDirectW)') 'select top ? * from Orders' (100,)

With top fixed or out it works fine.

Any ideas?

1 Answer 1

3

As indicated in this answer, assuming you are using at least SQL Server 2005, you should be able to run:

engine.execute(text('select top (:t) * from Orders'), t=100)

SQL Server should accept the parameter as long as it's enclosed in parentheses.

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

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.