SQL Novice
SQL Novice

Reputation: 323

SQL Select and Update command

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?

Upvotes: 1

Views: 112

Answers (7)

Praveen
Praveen

Reputation: 9335

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

Upvotes: 0

Prashant Mishra
Prashant Mishra

Reputation: 647

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

Upvotes: 0

zedfoxus
zedfoxus

Reputation: 37049

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.

Upvotes: 5

elzisiou
elzisiou

Reputation: 11

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

Upvotes: 1

apomene
apomene

Reputation: 14389

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

Upvotes: 0

Adam
Adam

Reputation: 2440

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.

Upvotes: 0

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

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 %

Upvotes: 1

Related Questions