PC Review


Reply
Thread Tools Rate Thread

WHERE criteria not act on

 
 
owilson
Guest
Posts: n/a
 
      5th Feb 2005
Hi,

I have the following SQL statement:

strSQL = "UPDATE BillingTable " _
& "SET Percentage = Jan " _
& "WHERE YearMonth = YearMonth;"

It works except that it updates all the records, not just
the ones where YearMonth = YearMonth.

Any suggestions would be greatly appreciated.
 
Reply With Quote
 
 
 
 
Chris2
Guest
Posts: n/a
 
      5th Feb 2005

"owilson" <(E-Mail Removed)> wrote in message
news:25ad01c50baf$226824c0$(E-Mail Removed)...
> Hi,
>
> I have the following SQL statement:
>
> strSQL = "UPDATE BillingTable " _
> & "SET Percentage = Jan " _
> & "WHERE YearMonth = YearMonth;"


owilson,

This Clause -->> WHERE YearMonth = YearMonth

*Always* evaluates True on all rows. This is because YearMonth is
always equal to itself, and therefore, always matching. Which is why
all rows are UPDATEed.


Sincerely,

Chris O.



>
> It works except that it updates all the records, not just
> the ones where YearMonth = YearMonth.
>
> Any suggestions would be greatly appreciated.



 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      5th Feb 2005
On Sat, 5 Feb 2005 10:18:47 -0800, "owilson"
<(E-Mail Removed)> wrote:

>Hi,
>
>I have the following SQL statement:
>
>strSQL = "UPDATE BillingTable " _
> & "SET Percentage = Jan " _
> & "WHERE YearMonth = YearMonth;"
>
>It works except that it updates all the records, not just
>the ones where YearMonth = YearMonth.
>
>Any suggestions would be greatly appreciated.


As Chris says, this is doing exactly what you're asking it to do:
updating every record where the value in the field yearmonth is equal
to itself!

What value of YearMonth do you want to select for updating? What's the
datatype of YearMonth, and where is your code getting the value?

Also, what do you want to set Percentage to? As it is, it will set it
to the value in the field BillingTable.Jan if there is such a field,
and give you an error if there's not. Is Jan a variable in your VBA
code, a form reference, or what?

John W. Vinson[MVP]
 
Reply With Quote
 
Owilson
Guest
Posts: n/a
 
      6th Feb 2005
Gentlemen,

Thank you for the help. If either one of you would like
to send me a 2 x 4, I'll gladly hit myself over the head
with it. (most times I don't mind being an idiot, but
sometimes it is embarrassing)

Thanks again,

Owen Wilson
>-----Original Message-----
>On Sat, 5 Feb 2005 10:18:47 -0800, "owilson"
><(E-Mail Removed)> wrote:
>
>>Hi,
>>
>>I have the following SQL statement:
>>
>>strSQL = "UPDATE BillingTable " _
>> & "SET Percentage = Jan " _
>> & "WHERE YearMonth = YearMonth;"
>>
>>It works except that it updates all the records, not

just
>>the ones where YearMonth = YearMonth.
>>
>>Any suggestions would be greatly appreciated.

>
>As Chris says, this is doing exactly what you're asking

it to do:
>updating every record where the value in the field

yearmonth is equal
>to itself!
>
>What value of YearMonth do you want to select for

updating? What's the
>datatype of YearMonth, and where is your code getting

the value?
>
>Also, what do you want to set Percentage to? As it is,

it will set it
>to the value in the field BillingTable.Jan if there is

such a field,
>and give you an error if there's not. Is Jan a variable

in your VBA
>code, a form reference, or what?
>
> John W. Vinson[MVP]
>.
>

 
Reply With Quote
 
Chris2
Guest
Posts: n/a
 
      6th Feb 2005

"Owilson" <(E-Mail Removed)> wrote in message
news:1d4c01c50be7$e0703c90$(E-Mail Removed)...
> Gentlemen,
>
> Thank you for the help. If either one of you would like
> to send me a 2 x 4, I'll gladly hit myself over the head
> with it. (most times I don't mind being an idiot, but
> sometimes it is embarrassing)
>
> Thanks again,
>
> Owen Wilson


Owen,

No worries.

As far as the 2 x 4 is concerned, an electronic version shall have to
do.

<2 x 4 />


Sincerely,

Chris O.


 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      6th Feb 2005
On Sat, 5 Feb 2005 17:04:58 -0800, "Owilson"
<(E-Mail Removed)> wrote:

>Gentlemen,
>
>Thank you for the help. If either one of you would like
>to send me a 2 x 4, I'll gladly hit myself over the head
>with it. (most times I don't mind being an idiot, but
>sometimes it is embarrassing)


Happens to all of us!

Glad it was a simple fix (once you saw past all those dratted trees
which were blocking the view of the forest...)

John W. Vinson[MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop Access re-arranging query criteria onto multiple criteria lines for OR condition Chrisso Microsoft Access 3 9th Nov 2007 11:50 AM
Query with criteria for long data type but criteria is double =?Utf-8?B?THluZGE=?= Microsoft Access Queries 1 30th Jan 2007 01:24 AM
Selection.AutoFilter Field / Criteria => criteria sometimes non-existing on worksheet markx Microsoft Excel Programming 1 24th Nov 2006 02:52 PM
Counting Cells with multiple criteria.One criteria supporting wild =?Utf-8?B?QXpoYXIgQXJhaW4=?= Microsoft Excel Worksheet Functions 1 12th Jan 2005 08:33 AM
Re: have input box. Need criteria entered to refer to cond. format criteria Bob Phillips Microsoft Excel Programming 0 1st Mar 2004 08:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.