Doug Evans
Doug Evans

Reputation: 1

simple syntax help for newbie

I have searched and not found any type of answer for this but when I try it in my phpmyadmin it tells me that the syntax is wrong. Could someone take a quick look and let me know what possibly could be wrong with this please:

UPDATE wellness_rsform_properties 
WHERE PropertyName = 'REQUIRED' 
AND PropertyValue = 'NO' 
REPLACE  (PropertyValue, 'NO', 'YES');

I would really appreciate any feedback!

Thanks, Doug

Upvotes: 0

Views: 56

Answers (6)

juergen d
juergen d

Reputation: 204756

UPDATE wellness_rsform_properties 
set PropertyValue = REPLACE (PropertyValue, 'NO', 'YES')
where PropertyName = 'REQUIRED' AND PropertyValue = 'NO';

Upvotes: 0

rkosegi
rkosegi

Reputation: 14638

Should be something like

UPDATE wellness_rsform_properties 
SET PropertyValue = REPLACE('NO', 'YES') 
WHERE PropertyName = 'REQUIRED' AND PropertyValue = 'NO'

How ever, you don't need to use replace, because you know new value of column, just update it:

UPDATE wellness_rsform_properties 
SET PropertyValue = 'YES' 
WHERE PropertyName = 'REQUIRED' AND PropertyValue = 'NO'

Upvotes: 1

Frankline
Frankline

Reputation: 40995

UPDATE wellness_rsform_properties
SET PropertyValue = REPLACE(PropertyValue, 'NO', 'YES') 
WHERE PropertyName = 'REQUIRED' 
AND PropertyValue = 'NO';

I believe this is what you are looking for.

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726569

UPDATE wellness_rsform_properties
SET PropertyValue = 'YES'
WHERE PropertyName = 'REQUIRED' AND PropertyValue = 'NO'

REPLACE function is not necessary because you compare PropertyValue = 'NO'. If you wanted to replace all occurrences of NO with YES, REPLACE would be applicable:

UPDATE wellness_rsform_properties
SET PropertyValue = REPLACE (PropertyValue, 'NO', 'YES')
WHERE PropertyName = 'REQUIRED' AND PropertyValue like '%NO%'

Upvotes: 1

Mithrandir
Mithrandir

Reputation: 25337

Do you mean?

UPDATE wellness_rsform_properties 
SET PropertyValue = 'YES'
WHERE PropertyName = 'REQUIRED' AND PropertyValue = 'NO';

Upvotes: 0

This should do what you seem to be trying

UPDATE wellness_rsform_properties
SET PropertyValue = 'YES'
WHERE PropertyName ='REQUIRED'
AND PropertyValue = 'NO';

Follow syntax

UPDATE <tables>
SET <field = value>
WHERE <criteria for which rows to update>

Upvotes: 0

Related Questions