By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,940 Members | 611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,940 IT Pros & Developers. It's quick & easy.

Can queries be re-used or should they be re-coded?

P: 16
Hi all,

I am wondering if I should re-type the SQL in my queries if I am using the same query as a sub-query in a different query.

An example:

I have a query, check_attendance
Expand|Select|Wrap|Line Numbers
  1. SELECT customerid, class_date, class_month FROM attendance
Now, say I have a second query, check_attendance_by_month
Expand|Select|Wrap|Line Numbers
  1. SELECT customerid, class_date, class_month FROM attendance WHERE class_month=[month]
In check_attendance_by_month Access will ask me which month I want attendance for.

However, I could simply code check_attendance_by_month as
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM check_attendance WHERE class_month = [month]
I know this approach works, but, is it advisable?

My biggest concern is whether changes to check_attendance will be reflected in check_attendance_by_month.

My second concern is whether this is a wise practice or not. On the one hand it means that each query is independent of each other so I can make changes to one without having to worry about the other. It does make for some monstrous (in terms of lines of code) queries though.

Thanks!
Jun 21 '12 #1
Share this Question
Share on Google+
1 Reply


TheSmileyCoder
Expert Mod 100+
P: 2,321
I think arguments can be mode for both cases. Making each query independent means that you don't accidentally screw something up when you make changes.

However it also means if you need to add an extra field say customerPhoneNumber you need to code it in to all of your queries.

I think its a matter of personal preference, and arguments can be made for both cases.
Jun 22 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.