So, putting all the comments I found correct together in a single answer, your code should probably look like this:
UPDATE bL SET
bL.[QUANTITY] = bL.[QUANTITY] + 2,
bL.[SERIAL_NUMBERS] =
(
CASE WHEN bL.[SERIAL_NUMBERS] IS NULL
THEN 'EOSB7U310007; EOSB7U310022'
ELSE bL.[SERIAL_NUMBERS] + '; EOSB7U310007; EOSB7U310022'
END
)
FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_BOXES_LINES] AS bL
LEFT JOIN [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_BOXES] AS bO
ON bL.[AOF_BOXES_ID] = bO.[ID]
AND bO.[SELECTED] = 'True'
However it can be shorten - like this:
UPDATE bL SET
bL.[QUANTITY] = bL.[QUANTITY] + 2,
bL.[SERIAL_NUMBERS] = ISNULL(bL.[SERIAL_NUMBERS] + '; ', '') + 'EOSB7U310007; EOSB7U310022'
FROM [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_BOXES_LINES] AS bL
LEFT JOIN [ROBOTICS_OPTICS_MECHUAT].[dbo].[AOF_BOXES] AS bO
ON bL.[AOF_BOXES_ID] = bO.[ID]
AND bO.[SELECTED] = 'True'
This is because it the value of bL.[SERIAL_NUMBERS]
is null then the concatenation of it with ;
will also be null.
Notes:
I've moved bO.[SELECTED] = 'True'
from the WHERE
clause to the ON
clause. This is because when using a left join, all the conditions on the right table should be on the ON
clause, otherwise the join is turned into an inner join.
Seems like you are using the bL.[SERIAL_NUMBERS]
column to store multiple values. This is a big mistake in 99.9999% of the cases.
Read Is storing a delimited list in a database column really that bad?, where you will see a lot of reasons why.