1

I need to update a column using the update statement.

SELECT *
FROM tng_managedobject 
WHERE severity <> 0 
  AND class_name like 'Plaza_VES_Junction_Box' 
  AND propagate_status <> 0

I need to update the propagate_status for all these classes to 0. How can I use the SQL update statement to do this?

1
  • 2
    What RDBMS do you use? Commented Jul 29, 2015 at 13:59

7 Answers 7

5

A simple update statement like this will do it:

update tng_managedobject 
set propagate_status = 0
where severity <> 0 
    and class_name = 'Plaza_VES_Junction_Box'
    and propagate_status <> 0

You don't need a LIKE clause when you are specifying the exact class name. = will suffice.

Sign up to request clarification or add additional context in comments.

Comments

1
update tng_managedobject
set propagate_status = 0
where severity <> 0 
and class_name like '%Plaza_VES_Junction_Box%' 
and propagate_status <> 0

For the class_name column, If you know the exact name, it is better to use =. If you are looking for a string that contains Plaza_VES_Junction_Box anywhere use %

Comments

1
UPDATE table1
SET table1.propagate_status = 0
FROM tng_managedobject AS table1
WHERE table1.severity <> 0 
AND table1.class_name like '%Plaza_VES_Junction_Box%' 
AND table1.propagate_status <> 0

1 Comment

Curious thing that you changed the pattern for like to include wildcards.
0
UPDATE tng_managedobject
SET propagate_status = 0
WHERE severity <> 0 AND class_name like('Plaza_VES_Junction_Box')

As @zedfoxus points out, you don't need a like statement. To maintain difference in answers, use his since it is more efficient than mine.

Comments

0
update tng_managedobject set  propagate_status=0    
where severity <> 0 and class_name like 'Plaza_VES_Junction_Box' 
and propagate_status <> 0

Comments

0
update tng_managedobject 
set propagate_status = 0
where severity <> 0 
  and class_name = 'Plaza_VES_Junction_Box'
  and propagate_status <> 0

1 Comment

update tablename(as mentioned in question) set columnname=value where <conditions(as given in question)> No need to use Like operator as the expression is 'Plaza_VES_Junction_Box' .like opr had worked well if expression would have '%Plaza_VES_Junction_Box%'.that's why I replaced that with '='
0
update tng_managedobject 
set propagate_status = 0 
where severity <> 0
and class_name like 'Plaza_VES_Junction_Box'
and propagate_status <> 0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.