Chris2015 Chris2015 - 1 year ago 72
SQL Question

Fixing syntax for UPDATE Query with SELECT Subquery

I am trying to

my dataset
condition is met using

UPDATE [Extract] SET [Type] = 'Main'
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 Source

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'.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download