1

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)

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
Erin Karschnik
  • 157
  • 2
  • 11

5 Answers5

5

Can this work?

update plantfunctiontable set decommissioned=1 where plantunitid  between 49 and 57
duffymo
  • 305,152
  • 44
  • 369
  • 561
2

You can use

Where plantunitid >= 49 AND plantunitid <= 57

OR

Where plantunitid BETWEEN 49 and 57
Kibbee
  • 65,369
  • 27
  • 142
  • 182
1

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
  • 3,178
  • 2
  • 19
  • 26
1

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
  • 2,053
  • 1
  • 14
  • 18
0

try

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

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

Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91