I have the following table and variable
DECLARE @FunctionValue nvarchar(255)
DECLARE @TSV_WithTarget TABLE
(
Transition_Set_Variable_ID INT,
[Value] nvarchar(255),
TargetTable nvarchar(255),
TargetColumn nvarchar(255),
FunctionValue nvarchar(255)
)
The table contains the following data :
IF (SELECT FunctionValue
FROM @TSV_WithTarget
WHERE Transition_Set_Variable_ID = @TSV_Target_Counter
AND FunctionValue IS NOT NULL ) IS NOT NULL
BEGIN
SELECT FunctionValue
FROM @TSV_WithTarget
END

apparently, this code right here produces the following error if I uncomment any of the commented out lines.
SET @FunctionValue = ( SELECT CASE
--WHEN FunctionValue LIKE 'DATEADD%' THEN ( SELECT FunctionValue
-- FROM @TSV_WithTarget
-- WHERE Transition_Set_Variable_ID = @TSV_Target_Counter )
WHEN FunctionValue LIKE 'GETDATE' THEN ( SELECT GETDATE() )
--WHEN FunctionValue LIKE 'STORED PROCEDURE' THEN ( SELECT Changed_In_SP
-- FROM BPE_T_VA_Transition_Set_Variable
-- WHERE Transition_Set_Variable_ID = @TSV_Target_Counter )
--WHEN FunctionValue LIKE 'SWITCH_USER' THEN ( SELECT 'hersem' )
WHEN FunctionValue LIKE 'VALUE' THEN ( SELECT Name
FROM BPE_T_VA_Value
WHERE Value_ID = ( SELECT Set_To_Value_ID
FROM BPE_T_VA_Transition_Set_Variable
WHERE Transition_Set_Variable_ID = @TSV_Target_Counter ) )
WHEN FunctionValue LIKE 'VARIABLE' THEN ( SELECT Value_ID
FROM BPE_T_VA_Process_Instance_Value
WHERE Variable_ID = ( SELECT Set_To_Variable_ID
FROM BPE_T_VA_Transition_Set_Variable
WHERE Transition_Set_Variable_ID = @TSV_Target_Counter )
AND Process_Instance_ID = @Process_Instance_ID)
--ELSE ( SELECT FunctionValue )
END AS FV
FROM @TSV_WithTarget
WHERE Transition_Set_Variable_ID = @TSV_Target_Counter
AND FunctionValue IS NOT NULL )
Msg 241, Level 16, State 1, Line 83
Conversion failed when converting datetime from character string.
I have no idea what this could be.
- The setting of @FunctionValue takes place in a WHILE loop.