PC Review


Reply
Thread Tools Rate Thread

How do I do this UPDATE in a single query?

 
 
E-Town
Guest
Posts: n/a
 
      6th Jan 2010
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [26] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='26')) ;
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [50] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='50')) ;
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[51] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='51')) ;
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[62] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='62')) ;
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[66] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='66')) ;
UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[80] = '1'
WHERE ((([HCPC struct 12-17-09].[Mod])='80')) ;

There's a way to do it in regular SQL server using CASE, but in Access it
doesn't work!

Thx
 
Reply With Quote
 
 
 
 
David C. Holley
Guest
Posts: n/a
 
      6th Jan 2010
Do you have fields named [26], [50], [51], etc.? If so why are they named as
such? Typically [HCPC struct 12-17-09]. [26] would be read as [table
name].[field name]

"E-Town" <(E-Mail Removed)> wrote in message
news:EA26B391-1C04-4A74-96B9-(E-Mail Removed)...
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [26] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='26')) ;
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [50] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='50')) ;
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[51] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='51')) ;
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[62] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='62')) ;
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[66] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='66')) ;
> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[80] = '1'
> WHERE ((([HCPC struct 12-17-09].[Mod])='80')) ;
>
> There's a way to do it in regular SQL server using CASE, but in Access it
> doesn't work!
>
> Thx



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      6th Jan 2010
On Wed, 6 Jan 2010 14:13:08 -0800, E-Town <(E-Mail Removed)>
wrote:

>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [26] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='26')) ;
>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [50] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='50')) ;
>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[51] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='51')) ;
>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[62] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='62')) ;
>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[66] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='66')) ;
>UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[80] = '1'
>WHERE ((([HCPC struct 12-17-09].[Mod])='80')) ;
>
>There's a way to do it in regular SQL server using CASE, but in Access it
>doesn't work!
>
>Thx


Access SQL and T/SQL are two different dialects. Two relevant differences are
that Access SQL does not allow multiple SQL commands in one query; another is
that Access does not support the CASE statement.

Your table with 80 (or more) fields named [26] and [50] and [80] and so on is
seriously denormalized, which is one reason you're having difficulty! How is
table [HCPC struct 12-17-09] related to other tables? Could its data be
generated by using a CROSSTAB query using [Mod] as the Column Header?
--

John W. Vinson [MVP]
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      7th Jan 2010
If for some reason you are stuck with the structure you have, you can use a
query like the following.

UPDATE [HCPC struct 12-17-09]
SET [HCPC struct 12-17-09].[26] = IIF([Mod]='26','1',[26])
, [HCPC struct 12-17-09].[50] = IIF([Mod]='50','1',[50])
, [HCPC struct 12-17-09].[51] = IIF([Mod]='51','1',[51])
, [HCPC struct 12-17-09].[62] = IIF([Mod]='62','1',[62])
, [HCPC struct 12-17-09].[66] = IIF([Mod]='66','1',[66])
, [HCPC struct 12-17-09].[80] = IIF([Mod]='50','1',[80])
WHERE [HCPC struct 12-17-09].[Mod] IN ('26','50','51','62','66','80')

Although, you might find it more efficient to run 6 separate queries instead
of running one query.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

> On Wed, 6 Jan 2010 14:13:08 -0800, E-Town <(E-Mail Removed)>
> wrote:
>
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [26] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='26')) ;
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09]. [50] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='50')) ;
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[51] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='51')) ;
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[62] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='62')) ;
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[66] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='66')) ;
>> UPDATE [HCPC struct 12-17-09] SET [HCPC struct 12-17-09].[80] = '1'
>> WHERE ((([HCPC struct 12-17-09].[Mod])='80')) ;
>>
>> There's a way to do it in regular SQL server using CASE, but in Access it
>> doesn't work!
>>

 
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
update query for multiple changes to a single field =?Utf-8?B?Umljaw==?= Microsoft Access Queries 7 6th Jul 2007 11:54 PM
Single Table Update Query =?Utf-8?B?QlNJTU9OUw==?= Microsoft Access Queries 4 5th Apr 2007 01:04 PM
Problem with Update Query Returning Message Re Single Row Update =?Utf-8?B?Q2hhcmxlcyBBbGxlbg==?= Microsoft Access Queries 1 6th Dec 2006 06:14 AM
RE: Single Table Update Query =?Utf-8?B?T2Zlcg==?= Microsoft Access Queries 0 7th Nov 2005 12:39 AM
Update Query on Single Record Michael Microsoft Access Queries 3 9th Oct 2003 02:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:46 PM.