views:

85

answers:

2

In an MS-Access database with Table called NewTable3

can i combine these 3 sql queries into one query

UPDATE NewTable3 SET SAO = '0' WHERE SAO LIKE '-';
UPDATE NewTable3 SET SAO = '0' WHERE SAO LIKE 'NULL';
UPDATE NewTable3 SET SAO = '0' WHERE SAO LIKE 'NA';
+4  A: 

What about using OR?

UPDATE NewTable3 
SET SAO = '0' 
WHERE (WAP LIKE '-') OR (WAP IS NULL) OR (WAP LIKE 'NA');

You can learn more about using AND and OR in SQL queries here.

The original question included the condition WAP LIKE 'NULL'. The correct notation is WAP IS NULL" and not WAP LIKE 'NULL'; Null isn't the text NULL but a special, none-textual value.

Adam Matan
thanks a lot both the answers are correct
silverkid
Certainly "WAP IS NULL" is the only valid notation. I think you should fix your SQL to be correct and point out the change in your comment. Otherwise, the non-careful reader could copy your invalid SQL above and then wonder why it's not working for them.
David-W-Fenton
Changed and added links to 'NULL (SQL)' at wikipedia.
Adam Matan
+4  A: 
UPDATE NewTable3 
SET SAO = '0' 
WHERE (WAP LIKE '-') OR (WAP IS NULL) OR (WAP LIKE 'NA');
Mitch Wheat
Adam was first, perhaps you could accept his answer....
Mitch Wheat
+1 for being a gent.
Adam Matan
The SQL is invalid, as "LIKE 'NULL'" will match nothing at all. You want "WAP Is Null". I'll hold off on a downvote until you fix it.
David-W-Fenton
@David W. Fenton: that's a string 'NULL', not an actual NULL
Mitch Wheat
Actually, it should be WAP = 'NULL' because the LIKE keyword isn't appropriate when matching a literal with no wildcard etc. However, the answer reflects the OP's SQL, so it isn't incorrect.
onedaywhen
I've updated to use the NULL value test rather than a string (as in posters original question)
Mitch Wheat
If you'd take an overview of @silverkid's posts over the last week, you'll see this question is a variation on several others, and that his sample data doesn't seem to be storing the string "Null" anywhere. It would be hard to guess from this one question whether the example query was correct for the data involved or if it just had rookie mistakes. From the context of the other posts, it seemed obvious to me that he really wasn't looking for the literal string "Null".
David-W-Fenton
@David: "If you'd take an overview of @silverkid's posts over the last week" - not something I usually do!
Mitch Wheat
@Mitch Wheat: same here. @David W. Fenton: with your enhanced knowledge of the context, you should edit the question. Otherwise we don't stand a chance of coming up with an answer which pleases you!
onedaywhen