我有下表和变量
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)
)
该表包含以下数据:
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
显然,如果我取消注释任何已注释掉的行,则此处的代码会产生以下错误。
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.
我不知道这可能是什么。
- @FunctionValue 的设置发生在 WHILE 循环中。