views:

74

answers:

5
+1  Q: 

Update Statements

Hi. 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  A: 

Can this work?

update plantfunctiontable set decommissioned=1 where plantunitid  between 49 and 57
duffymo
you beat me to it...
Eppz
Dido. +1 for speed.
rlb.usa
+1  A: 

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)

Eppz
+2  A: 

You can use

Where plantunitid >= 49 AND plantunitid <= 57

OR

Where plantunitid BETWEEN 49 and 57
Kibbee
A: 

hey there, try

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

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

N8
+1  A: 

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)
Nathan