maintain query formatting ?

james_lankford

Well-known Member
Joined
Jan 11, 2009
Messages
1,191
I write a bunch of queries using straight sql, without the query designer

I'll write the query, run it, save the query
everything's fine

then I come back a week later to run the query again (except this time I want to change the "order by" or maybe change one thing in the "where")

so I open the query in sql view and ...

half the time it opens all nice and pretty, just the way I wrote it, just the way I saved it

Code:
select 
  field1, 
  field2
  count(*) as number_of
from
  some_table 
    as tbl 
where 
(
  (
    tbl.field3 = "x"
  ) 
  and 
  (
    tbl.field4 = "y"
  )
)
group by 
  field1, 
  field2

and half the time it opens like this

Code:
select field1, field2 count(*) as number_of from some_table as tbl where ((tbl.field3="x") and (tbl.field4="y")) group by field1, field2

WHY WHY WHY does it do that !!!

I cannot figure out why it sometimes keeps the formatting and why sometimes it doesn't

it's gotten to the point where I don't even save my queries in access anymore
I just save them a text file and open, copy, paste when I need them
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
59,532
Office Version
  1. 365
Platform
  1. Windows
If you are editing your query that much, you may want to change your approach. Many programmers will create a "Selection Form", where they use a form to set their Selection Criteria (i.e. "WHERE" clause), and then have VBA build and apply the SQL code you need for that.
 

Forum statistics

Threads
1,144,619
Messages
5,725,331
Members
422,617
Latest member
rahul27ragit

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top