Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does OPENQUERY not accept variables?

I am well aware that MS SQL Server does not allow variables to be used in the OPENQUERY statement and I'm aware of the workarounds.

What I'd like to know is, does anyone know WHY variables or concatenated strings are not allowed?

The hoops this causes people to jump through is simply astounding and it just isn't in line with other functions such as EXEC.

Can anyone comment on this? Who do I have to bribe at MS to get his sorted out?

like image 354
Andrew Avatar asked Oct 31 '25 18:10

Andrew


1 Answers

The limitation is caused by the way linked servers are implemented in SQL Server, and the way its dependant libraries work. There is a whole chain of libraries used to pass your SQL Command, all of them have different variable sizes and cache sizes. Some of the limitations are in the OCBC drivers themselves, so 8k is a safe bet from Microsoft. Not allowing you to pass variables just enforces the 8k limit rule.

like image 173
Dan S Avatar answered Nov 03 '25 09:11

Dan S