Some "cleaner" IMHO SQL is to do something like
This may be personal but I find it promotes readability of your code
Also... Big SQLs like this I tend to write like:
Again going towards readability
Also this (or simular) syntax will allow you to add/remove where clauses as you require/desire... Simply build a where clause something like:
Then in your sql insert/add the where clause... removing the leading AND
If your not sure if there is a where it gets a little more complex but if there is always some you can addapt this to your needs
Then finaly...
You are still using the linked view in access, instead of using a Pass through query as I suggested in my previous post
Using a PT query will increase performance even more
Code:
Select groupbyfield1, groupbyfield2, groupbyfield...., sum(), avg(), ...
From
Group by groupbyfield1, groupbyfield2, groupbyfield....
Also... Big SQLs like this I tend to write like:
Code:
mYSQL = mySQL & " SELECT Month([casedate]) as cMonth "
mYSQL = mySQL & " , HD.Hosp "
mYSQL = mySQL & " , Sum(HD.Onvent) as Onvent "
mYSQL = mySQL & " , Sum(HD.TotalDeath) as TotalDeath "
mYSQL = mySQL & " , Sum(HD.TE_Timely) as TE_Timely "
...
Also this (or simular) syntax will allow you to add/remove where clauses as you require/desire... Simply build a where clause something like:
Code:
if not isnull(somevariable) then
myWHERE = myWHERE & " AND THISFIELD = '" & somevariable & "' "
end if
etc...
Code:
mySQL = mySQL & " WHERE " & mid(myWHERE, 4)
Then finaly...
Code:
"FROM dbo_HD_Summary HD "
Using a PT query will increase performance even more