maintain query formatting ?

james_lankford

Well-known Member
Joined
Jan 11, 2009
Messages
1,223
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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

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
Back
Top