Sql-server – Dynamically changing an order number to end in _ERR

sql serverupdate

I'm trying to update multiple orders at once instead of doing them one at a time. Is there a way to dynamically update them all at once?

For example: I have 5 orders ABC, BCD, CDE, DEF, EFG.

I need to update them to look like this ABC_ERR, BCD_ERR, CDE_ERR, etc.

Best Answer

It's going to be a different concatenation operator depending on the RDMS you're using. For instance:

  • Oracle uses ||
  • SQL Server uses +
  • MySQL uses concat

...but everything else looks like:

UPDATE table1 SET order = order ||'_ERR' WHERE [your condition]

Since the question is tagged for SQL Server, the applicable syntax is:

UPDATE table1 SET order = order +'_ERR' WHERE [your condition]