I’m trying an update with a conditional sub-select which could return null…
UPDATE
aTable SET
aColumn =
(
SELECT TOP 1
CASE
WHEN bTable.someColumn = 1 THEN someValue1
WHEN bTable.someColumn = 2 THEN someValue2
ELSE someValue3
END
FROM
bTable
WHERE
bTable = @someCriteria
ORDER BY
someSortColumn
) WHERE
aTable.id = @someId;
If the “bTable = @someCriteria” clause causes no results to be returned from the SELECT, it attempts to insert a NULL into “aColumn”, which in this case is a NOT NULL column.
Question
How do I get it to simply leave “aColumn” alone in this circumstance?
Many thanks.
1 Answer