开发者

How to stop MS Access from changing my SQL code?

开发者 https://www.devze.com 2023-02-24 11:29 出处:网络
I\'v开发者_运维问答e wrote an SQL query in MS Access and Access made a mess of it, only to show it \"graphical\".

I'v开发者_运维问答e wrote an SQL query in MS Access and Access made a mess of it, only to show it "graphical". How do I stop it from doing this?


There's no stopping Access from changing your SQL if you save it as a QueryDef object (ie, using the graphical query editor). You have (at least) two other options:

  1. Build your queries in VBA
  2. Store your queries in a table dedicated to queries using a Memo field to store the SQL (this will also require some VBA to take the SQL and execute it or assign it to a temporary querydef, etc.)

You can still use the QBE (query-by-example) window to generate your SQL initially if you want.

Also, if you have a non-Jet backend (MS SQL Server, for example) you can write pass-through queries. You lose the graphical interface but gain all of the functionality of writing SQL in your backend of choice. Access won't rearrange the formatting on pass-through queries.


Here's a dirty trick : append an UNION at the end of the query which is always FALSE.

SELECT field_1, field_2 
FROM my_table
UNION select field_1, field_2 FROM my_table WHERE False = True;

That's horrible and I'm ashamed to do something like that but it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消