Chris2015 Chris2015 - 1 month ago 6
SQL Question

Fixing syntax for UPDATE Query with SELECT Subquery

I am trying to

UPDATE
my dataset
WHERE
a
SELECT
condition is met using
Instr
.

UPDATE [Extract] SET [Type] = 'Main'
WHERE
SELECT Instr([Name],'Main')
FROM [Extract]>0;


I think it's possible to do this using my SQL above, but I am running syntax issues. Can anyone help me correct this?

Thank you!

Answer

If you're trying to do your update to records where [Name] contains 'Main', you can do it in a simpler way without a SELECT at all. Use like() and the * wildcard. Like this:

UPDATE [Extract] 
SET [Type] = 'Main'
WHERE [Name] like ('*Main*')

* allows for any character string to exist on either side of the string 'Main'.

Comments