Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Combine query updates?

Author  Topic 

renecarol
Starting Member

5 Posts

Posted - 2011-08-31 : 16:34:47
I always have to run multiple queries to update things because I don't know how to nest if/then in an update in Access SQL. There has got to be some way to combine these to do one update:

UPDATE CovElig AS cel

SET cel.GrpNmeCd = 001

WHERE (Mid([cel].[GrpName],10,1)="S"));

UPDATE CovElig AS cel

SET cel.GrpNmeCd = 006

WHERE (Mid([cel].[GrpName],10,1)="B"));
UPDATE CovElig AS cel

SET cel.GrpNmeCd = 910

WHERE (Mid([cel].[GrpName],10,1)=""));

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-31 : 16:55:30
This should work as a single UPDATE:
UPDATE CovElig 
SET CovElig.GrpNmeCd = Switch(Mid([GrpName],10,1)="S","001", Mid([GrpName],10,1)="B","006", Mid([GrpName],10,1)="","910")
WHERE Mid([GrpName],10,1) In ("S","B","");
Go to Top of Page
   

- Advertisement -