0
제가 작업하고있는 저장 프로 시저가 있는데 프로 시저 내에서 만든 테이블 변수에 저장된 결과를 반환하려고합니다. 어떤 이유로, 프로 시저를 실행할 때 아무 것도 반환하지 않습니다. 그러나, 나는 테이블 변수를 채우고 작동 과정에서 그것을 가지고하는 데 사용되는 코드의 조각을 ... 가지고가는 경우에테이블 변수에서 결과를 반환하지 않는 저장 프로 시저?
다음과 같이 코드는 다음과 같습니다
테스트 코드
DECLARE @RC int
DECLARE @constraint_names nvarchar(max)
DECLARE @column_names nvarchar(max)
DECLARE @table_name nvarchar(max)
DECLARE @table_schema nvarchar(max)
DECLARE @database_name nvarchar(max)
DECLARE @debug int
DECLARE @ExistFlag int;
-- TODO: Set parameter values here.
SET @column_names = 'M2016_Object_ID int, Name varchar(50), a int, b'
SET @table_name = 'tblM2016_Objects';
SET @debug = 0;
SET @ExistFlag = 1;
DECLARE @existing_cols TABLE (Value nvarchar(max));
INSERT INTO @existing_cols EXEC spM2016_CheckColumnExistence_tblM2016
@column_names, @table_name, @database_name, @table_schema, 1, 0;
select * from @existing_cols
결과
Value
M2016_Object_ID int
Name varchar(50)
내가 테스트 해요 때문에 예상 된 결과입니다 tblM2016_Objects 테이블에 M2016_Object_ID 및 Name 열이 있는지 확인합니다.
그러나이 작업을 저장 프로 시저 내에서 실행하면 아무 것도 반환하지 않습니다. 절차
ALTER PROCEDURE spM2016_ChangePKConstraints_tblM2016
-- Add the parameters for the stored procedure here
@constraint_names nvarchar(max) =
N'PK_tblM2016_Fields_M2016_Field_ID',
@column_names nvarchar(max) = N'M2016_Field_ID',
@table_name nvarchar(max) = N'tblM2016_Fields',
@table_schema nvarchar(max) = N'dbo',
@database_name nvarchar(max) = N'MET',
@debug int = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @tbl_name nvarchar(max) = N'tblM2016_Fields',
@col_names nvarchar(max) = N'M2016_Field_ID',
@tbl_schema nvarchar(max) = N'dbo',
@db_name nvarchar(max) = N'MET',
@tbl_full_name nvarchar(max),
@tbl_short_name nvarchar(max),
@sql nvarchar(max),
@params nvarchar(max)
-- Insert statements for procedure here
SET @col_names = ISNULL(NULLIF(@column_names, ''), @col_names);
SET @tbl_name = quotename(ISNULL(NULLIF(@table_name, ''), @tbl_name));
SET @tbl_schema = quotename(ISNULL(NULLIF(@table_schema, ''), @tbl_schema));
SET @db_name = quotename(ISNULL(NULLIF(@database_name, ''), @db_name));
SET @tbl_full_name = @db_name + '.' + @tbl_schema + '.' + @tbl_name;
SET @tbl_short_name = @tbl_schema + '.' + @tbl_name;
DECLARE @existing_cols TABLE (Value nvarchar(max));
DECLARE @nonexisting_cols TABLE (Value nvarchar(max));
--INSERT INTO @split_columns
-- SELECT *
-- FROM
-- fnM2016_Split_String_Inline(@col_names, ',');
--IF (@debug = 1)
-- SELECT * FROM @split_columns;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE type = 'PK' AND parent_object_id = OBJECT_ID(@tbl_full_name))
BEGIN
-- No PK constraint, check col_names to see which exist and don't exist
INSERT INTO @existing_cols EXEC spM2016_CheckColumnExistence_tblM2016 @col_names, @tbl_name, @db_name, @tbl_schema, 1, 0;
INSERT INTO @nonexisting_cols EXEC spM2016_CheckColumnExistence_tblM2016 @col_names, @tbl_name, @db_name, @tbl_schema, 0, 0;
SELECT * FROM @existing_cols;
SELECT * FROM @nonexisting_cols;
END
--ELSE
--BEGIN
--END
END
결과 를 저장
이들은 위 시험에서 같은 파라미터 값을 사용하여 처리를 실행 한 후 결과이다 :
EXECUTE @RC = [dbo].[spM2016_ChangePKConstraints_tblM2016]
@constraint_names
,@column_names
,@table_name
,@table_schema
,@database_name
,@debug;
결과
Value
N'tblM2016_Fields''을하지만, '해야한다 :
은 테이블 변수와는 아무 상관이 없었 밝혀 tblM2016_Objects' –
'spM2016_ChangePKConstraints_tblM2016' 절차로 전달할 실제 값을 표시 할 수 있습니까? –
테스트 코드 블록에서 사용되는 매개 변수는 spM2016_ChangePKConstraints_tblM2016에 전달되는 매개 변수와 동일합니다. – Jake