Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use variables in sql queries except in where clause #4938

Closed
Dilhasha opened this issue Oct 16, 2023 · 2 comments
Closed

Cannot use variables in sql queries except in where clause #4938

Dilhasha opened this issue Oct 16, 2023 · 2 comments

Comments

@Dilhasha
Copy link

Description:

int batchSize = 70;
.....
sql:ParameterizedQuery sqlQuery = `SELECT TOP ${batchSize} guid , date FROM MigrationRecords`

This gives an error as follows.

Incorrect syntax near '@P0'.. {"errorCode":102,"sqlState":"S0001"}

When the batchSize is hard coded in the query, this works fine. If the variable is in where clause, it doesn't give any error and picks up the value.

Steps to reproduce:

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@Dilhasha
Copy link
Author

Workaround:
Use OFFSET 0 ROWS FETCH FIRST ${batchSize} ROWS ONLY; instead of TOP ${batchSize}

@niveathika
Copy link
Contributor

This is the expected behaviour as top clause value cannot be parameterized i.e it cannot be a user insertions at runtime.

Database expects the top clause value at compile time and this needs to be available in the query.

@niveathika niveathika closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants