我有以下表和變量轉換失敗
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循環中。
'將nvarchar值'04/29/2013'轉換爲數據類型int.' – hermann 2013-04-29 11:05:53
並替換CAST上的Value_ID(Value_ID AS nvarchar(255)) – 2013-04-29 11:08:22
轉換失敗,請將其添加到您的原始答案。謝謝。 – hermann 2013-04-29 11:12:40