Value_ID - ( Set_To_Value_ID goes here ) Manual_Value
Set_To_Variable_ID, Changed_In_SP OR Comment_Input goes here )
You can use the COALESCE
expression like so:
INSERT INTO Processes
SELECT
Set_To_Value_ID,
COALESCE(Set_To_Variable_ID, Changed_In_SP, Comment_Input)
FROM Variables
Update: Well, since you couldn't use the COALESCE
for this, here is the canonical way to do that using the CASE
expression:
INSERT INTO Processes
SELECT
Set_To_Value_ID,
CASE
WHEN Set_To_Variable_ID IS NOT NULL THEN Set_To_Variable_ID
WHEN Changed_In_SP IS NOT NULL THEN Changed_In_SP
WHEN Comment_Input IS NOT NULL THEN Comment_Input
END
FROM Variables