我花了最后3个小时试图弄清问题是什么,但不幸的是,没有成功。
以下是相关代码:
DECLARE @_l_Results_Table TABLE ( Code nvarchar(32) ,
Name nvarchar(64) ,
Zone int ,
Source_Type nvarchar(16) ,
Object_Type nvarchar(16)
) ;
INSERT @_l_Results_Table
SELECT Code , Name , Zone , Source_Type , Object_Type
FROM [UWQ].[T_DATA_Object_Sources]
WHERE CODE = 'AB0045';
SELECT 'Code' AS Field_Name ,
CAST(Code AS NVARCHAR) AS Field_Value ,
'Y' AS Protected ,
'Text' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Name' AS Field_Name ,
CAST(REPLACE(REPLACE(Name,'\','\\'),'"','\"') AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Text' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Zone' AS Field_Name ,
CAST(Zone AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Source_Type' AS Field_Name ,
CAST(Source_Type AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Object_Type' AS Field_Name ,
CAST(Object_Type AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table ;
当我在Management Studio中以匿名块的形式运行它时,它会产生预期的结果。
当我运行具有此代码的存储过程时,我收到错误" 消息213,级别16,状态7,过程p_DATA_Get_Object_Source_Details,第62行 列名或提供的值数与表定义不匹配。" 。
此代码与完整过程的唯一区别是过程声明和设置OUT参数(标量)。
我非常感谢任何帮助。
修改:
以下是完整存储过程的代码:
ALTER PROCEDURE [UWQ].[p_DATA_Get_Object_Source_Details] (
--CREATE PROCEDURE [UWQ].[p_DATA_Get_Object_Source_Details] (
@_l_Object_Source_Code NVARCHAR(64) ,
@_l_Result_Code INT OUTPUT ,
@_l_Result_Message NVARCHAR(2000) OUTPUT )
AS
BEGIN
DECLARE @_l_Results_Table TABLE ( Code nvarchar(32) ,
Name nvarchar(64) ,
Zone int ,
Source_Type nvarchar(16) ,
Object_Type nvarchar(16)
) ;
INSERT @_l_Results_Table
SELECT Code , Name , Zone , Source_Type , Object_Type
FROM [UWQ].[T_DATA_Object_Sources]
WHERE CODE = 'AB0045';
SELECT 'Code' AS Field_Name ,
CAST(Code AS NVARCHAR) AS Field_Value ,
'Y' AS Protected ,
'Text' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Name' AS Field_Name ,
CAST(REPLACE(REPLACE(Name,'\','\\'),'"','\"') AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Text' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Zone' AS Field_Name ,
CAST(Zone AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Source_Type' AS Field_Name ,
CAST(Source_Type AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table
UNION ALL
SELECT 'Object_Type' AS Field_Name ,
CAST(Object_Type AS NVARCHAR) AS Field_Value ,
'N' AS Protected ,
'Select' AS Datatype ,
'' AS Min_Value ,
'' AS Max_Value ,
'' AS Step_Size ,
'0' AS Group_ID FROM @_l_Results_Table ;
SET @_l_Result_Code = 0 ;
Procedure_Completion:
RETURN ;
END
GO
答案 0 :(得分:0)
问题是由于我用来测试SP的匿名块一旦从两个返回的列更改为8(实际需要),就没有更新。
在适应匿名块中接收结果的临时表之后,所有工作都干净利落。
感谢所有那些愿意投入精力去帮助的人,特别是TriV,他提出了引起我注意的问题,即SP的召唤。