Update Statements

225 Views Asked by At

I am a beginner SQL user (not formally trained; OJT only) and need some assistance with a simple update statement. I would like to write an update statement that allows me to list ID's. The statement shown below is how I am currently writing it. Ideally, the statement would allow me to write it like "where plantunitid in (49-57). Is there a way to do this? Thanks for any assistance provided.

update plantfunctiontable set decommissioned=1 where plantunitid in (49,50,51,52,53,54,55,56,57)

5

There are 5 best solutions below

0
On BEST ANSWER

Can this work?

update plantfunctiontable set decommissioned=1 where plantunitid  between 49 and 57
0
On

That should work as is.

Or you can do it like this.

Update planfunctiontable set decommissioned = 1 where plantunitid between 49 and 57

assuming that your range will always be sequential (1,2,3....7,8,9)

0
On

You can use

Where plantunitid >= 49 AND plantunitid <= 57

OR

Where plantunitid BETWEEN 49 and 57
0
On

try

Update plantfunctiontable
SET decommissioned = 1
WHERE plantunitid >= @startID
AND plantunitid <= @endID

where @startID and @endID are your statements parameters. hope that helps

0
On

Only if it's sequential, can you use that.

UPDATE plantfunctiontable
   SET decommissioned = 1
 WHERE plantunitid BETWEEN 49 AND 57

If not sequential, your original query works fine

UPDATE plantfunctiontable
   SET decommissioned = 1
 WHERE plantunitid IN (49, 50, 51, 52, 53, 54, 55, 56, 57)