A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Run 3 update queries at once



 
 
Thread Tools Display Modes
  #1  
Old December 29th, 2009, 10:18 PM posted to microsoft.public.access.queries
ironwood9 via AccessMonster.com
external usenet poster
 
Posts: 52
Default Run 3 update queries at once

I have a table with three Yes/No fields used as “flags” …. I run a update
queries to set the value of these fields to True if certain criteria is met.
There are three update queries with slightly different criteria, and each one
updates a different one of the 3 yes/no fields – is there a way to combine
the 3 queries ?
The function named fNetWorkDays calculates the number of working days
– if the number equals 3, then I want to check the “Call1” field in tblMain.
If the number equals 6, then I want to check the “Call2” field, and so on –
here’s the code for the 3 queries:

Query 1:
UPDATE tblMain SET tblMain.Call1 = -1, tblMain.DateUpdated = Now()
WHERE (((tblMain.Call1)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
3))

Query 2:
UPDATE tblMain SET tblMain.Call2 = -1, tblMain.DateUpdated = Now()
WHERE (((tblMain.Call2)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
6
));

Query 3:
UPDATE tblMain SET tblMain.Call3 = -1, tblMain.DateUpdated = Now(),
WHERE (((tblMain.Call3)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
9
));

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #2  
Old December 29th, 2009, 10:20 PM posted to microsoft.public.access.queries
ironwood9 via AccessMonster.com
external usenet poster
 
Posts: 52
Default Run 3 update queries at once

ironwood9 wrote:
I have a table with three Yes/No fields used as “flags” …. I run a update
queries to set the value of these fields to True if certain criteria is met.
There are three update queries with slightly different criteria, and each one
updates a different one of the 3 yes/no fields – is there a way to combine
the 3 queries ?
The function named fNetWorkDays calculates the number of working days
– if the number equals 3, then I want to check the “Call1” field in tblMain.
If the number equals 6, then I want to check the “Call2” field, and so on –
here’s the code for the 3 queries:

Query 1:
UPDATE tblMain SET tblMain.Call1 = -1, tblMain.DateUpdated = Now()
WHERE (((tblMain.Call1)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
3))

Query 2:
UPDATE tblMain SET tblMain.Call2 = -1, tblMain.DateUpdated = Now()
WHERE (((tblMain.Call2)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
6));

Query 3:
UPDATE tblMain SET tblMain.Call3 = -1, tblMain.DateUpdated = Now(),
WHERE (((tblMain.Call3)=0) AND ((fNetWorkdays([DtStartDate],Date(),True))=
9));


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #3  
Old December 29th, 2009, 10:42 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Run 3 update queries at once

ironwood9 via AccessMonster.com wrote:
I have a table with three Yes/No fields used as "flags" .. I run a
update queries to set the value of these fields to True if certain
criteria is met. There are three update queries with slightly
different criteria, and each one updates a different one of the 3
yes/no fields - is there a way to combine the 3 queries ?
The function named fNetWorkDays calculates the number of
working days - if the number equals 3, then I want to check the
"Call1" field in tblMain. If the number equals 6, then I want to
check the "Call2" field, and so on - here's the code for the 3
queries:

Query 1:
UPDATE tblMain SET tblMain.Call1 = -1, tblMain.DateUpdated =
Now() WHERE (((tblMain.Call1)=0) AND
((fNetWorkdays([DtStartDate],Date(),True))= 3))

Query 2:
UPDATE tblMain SET tblMain.Call2 = -1, tblMain.DateUpdated =
Now() WHERE (((tblMain.Call2)=0) AND
((fNetWorkdays([DtStartDate],Date(),True))= 6));

Query 3:
UPDATE tblMain SET tblMain.Call3 = -1, tblMain.DateUpdated =
Now(), WHERE (((tblMain.Call3)=0) AND
((fNetWorkdays([DtStartDate],Date(),True))= 9));

Well, it might be possible, but it might not perform as well as running
the 3 separate queries would. You see, each of those 3 queries is
limiting the rows affected by the value of the CallN field, thus saving
you from scanning the entire table. In order to combine these updates
into one, we are now going to be forced to scan the entire table. Here
is one way to do it:

UPDATE tblMain
SET
[Call1] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 3,-1,[Call1] ),
[Call2] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 6,-1,[Call2] ),
[Call3] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 9,-1,[Call3] ),
DateUpdated =Now()
WHERE fNetWorkdays([DtStartDate],Date(),True) IN (3,6,9)

Give it a try and, if it takes forever to run, don't say I didn't warn
you :-)


--
HTH,
Bob Barrows


  #4  
Old December 29th, 2009, 11:10 PM posted to microsoft.public.access.queries
ironwood9 via AccessMonster.com
external usenet poster
 
Posts: 52
Default Run 3 update queries at once

Bob,
Thanks ! Actually, the version I'm using right now is a scaled down version,
so as for performance, I don't think it's going to be an issue anyway - but
I'll have to cross that bridge.

One thing I left out is the fact that IF the Call3 field is being set to -1,
THEN I want another field (LastCallDt) in tbl Main to be populated with the
current date. Is that possible ?

Thanks for your help !


Bob Barrows wrote:
I have a table with three Yes/No fields used as "flags" .. I run a
update queries to set the value of these fields to True if certain

[quoted text clipped - 21 lines]
Now(), WHERE (((tblMain.Call3)=0) AND
((fNetWorkdays([DtStartDate],Date(),True))= 9));


Well, it might be possible, but it might not perform as well as running
the 3 separate queries would. You see, each of those 3 queries is
limiting the rows affected by the value of the CallN field, thus saving
you from scanning the entire table. In order to combine these updates
into one, we are now going to be forced to scan the entire table. Here
is one way to do it:

UPDATE tblMain
SET
[Call1] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 3,-1,[Call1] ),
[Call2] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 6,-1,[Call2] ),
[Call3] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 9,-1,[Call3] ),
DateUpdated =Now()
WHERE fNetWorkdays([DtStartDate],Date(),True) IN (3,6,9)

Give it a try and, if it takes forever to run, don't say I didn't warn
you :-)


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #5  
Old December 30th, 2009, 12:03 AM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Run 3 update queries at once

It's pretty much the same formula as that used to update Call3 (with two
changes). See if you can figure it out.
ironwood9 via AccessMonster.com wrote:
Bob,
Thanks ! Actually, the version I'm using right now is a scaled down
version, so as for performance, I don't think it's going to be an
issue anyway - but I'll have to cross that bridge.

One thing I left out is the fact that IF the Call3 field is being set
to -1, THEN I want another field (LastCallDt) in tbl Main to be
populated with the current date. Is that possible ?

Thanks for your help !


Bob Barrows wrote:
I have a table with three Yes/No fields used as "flags" .. I run a
update queries to set the value of these fields to True if certain

[quoted text clipped - 21 lines]
Now(), WHERE (((tblMain.Call3)=0) AND
((fNetWorkdays([DtStartDate],Date(),True))= 9));


Well, it might be possible, but it might not perform as well as
running
the 3 separate queries would. You see, each of those 3 queries is
limiting the rows affected by the value of the CallN field, thus
saving
you from scanning the entire table. In order to combine these updates
into one, we are now going to be forced to scan the entire table.
Here
is one way to do it:

UPDATE tblMain
SET
[Call1] = Iif(fNetWorkdays([DtStartDate],Date(),True)= 3,-1,[Call1]
), [Call2] = Iif(fNetWorkdays([DtStartDate],Date(),True)=
6,-1,[Call2] ), [Call3] =
Iif(fNetWorkdays([DtStartDate],Date(),True)= 9,-1,[Call3] ),
DateUpdated =Now()
WHERE fNetWorkdays([DtStartDate],Date(),True) IN (3,6,9)

Give it a try and, if it takes forever to run, don't say I didn't
warn
you :-)


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #6  
Old December 30th, 2009, 12:44 AM posted to microsoft.public.access.queries
ironwood9 via AccessMonster.com
external usenet poster
 
Posts: 52
Default Run 3 update queries at once

Bob,
Would it be:
[Call3] = Iif(fNetWorkdays([LastCallDt],Date(),True)= 9,Date(),[Call3] ),

???


Bob Barrows wrote:
It's pretty much the same formula as that used to update Call3 (with two
changes). See if you can figure it out.
Bob,
Thanks ! Actually, the version I'm using right now is a scaled down

[quoted text clipped - 35 lines]
warn
you :-)



--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #7  
Old December 30th, 2009, 12:53 AM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Run 3 update queries at once

Well ... no. The field you want to update is not [Call3], is it. And you
don't want to set that field's value to [Call3] 's value, do you? :-)

OK, you've given it a try, so here's the answer:

[LastCallDt] = Iif(fNetWorkdays([DtStartDate],Date(),True)=
9,Date(),[LastCallDt] )

In English, this says:
set the value of LastCallDt to today's date if
fNetWorkdays([DtStartDate],Date(),True)= 9, otherwise leave it alone (set
its value to itself)



ironwood9 via AccessMonster.com wrote:
Bob,
Would it be:
[Call3] = Iif(fNetWorkdays([LastCallDt],Date(),True)=
9,Date(),[Call3] ),

???


Bob Barrows wrote:
It's pretty much the same formula as that used to update Call3 (with
two changes). See if you can figure it out.
Bob,
Thanks ! Actually, the version I'm using right now is a scaled down

[quoted text clipped - 35 lines]
warn
you :-)


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #8  
Old December 30th, 2009, 12:57 AM posted to microsoft.public.access.queries
ironwood9 via AccessMonster.com
external usenet poster
 
Posts: 52
Default Run 3 update queries at once

Bob,
I tried, sorry - I know the syntax for one immediate if, where you have the
arg,the condition, and the result if true, if false, but in this case, I
don't get it - I don't understand why you put the field name twice -
obviously you do...

In English, the one part says:
Set the field named Call3 equal to TRUE IF the result of the function is
equal to 9, and leave it set to FALSE if the result of the function's
calculation is NOT equal to 9.

I get the first part - the what - like SET fieldname = to whatever, but
what's the significance of stating the fieldname again ?



???

It's pretty much the same formula as that used to update Call3 (with two
changes). See if you can figure it out.

[quoted text clipped - 3 lines]
warn
you :-)


--
Message posted via http://www.accessmonster.com

  #9  
Old December 30th, 2009, 01:02 AM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Run 3 update queries at once

Did my previous reply help?


ironwood9 via AccessMonster.com wrote:
Bob,
I tried, sorry - I know the syntax for one immediate if, where you
have the arg,the condition, and the result if true, if false, but in
this case, I don't get it - I don't understand why you put the field
name twice - obviously you do...

In English, the one part says:
Set the field named Call3 equal to TRUE IF the result of the function
is equal to 9, and leave it set to FALSE if the result of the
function's calculation is NOT equal to 9.

I get the first part - the what - like SET fieldname = to whatever,
but what's the significance of stating the fieldname again ?



???

It's pretty much the same formula as that used to update Call3
(with two changes). See if you can figure it out.

[quoted text clipped - 3 lines]
warn
you :-)


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:58 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.