I created my stored procedure according to this sample. but I do not understanding why it keep give me error for @xquiz is not declarated.
Here is my code.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*. according the due date end user select and ALTER temp table
find the nomatch table in the occh and return the table
*/
ALTER PROCEDURE dbo.test2
@quiz VARCHAR( 25 ),
@debug bit = 0
as
DECLARE @sql nvarchar(4000),
@paramlist nvarchar(4000)
begin
CREATE TABLE #tmpTrained(
EmplID char(30))
set @sql='select distinct EmplNO from tblCurrentWinTrainingLog where 1=1'
set @sql= @sql+ ' AND quizname = @xquiz '
IF @Debug = 1
BEGIN
PRINT @sql PRINT ''
END
set @sql='Insert into #tmpTrained '+ @sql
exec (@sql)
set @sql='select * from #tmpTrained '
exec (@sql)
SELECT @paramlist = '@xquiz varchar(25)'
EXEC sp_executesql @sql, @paramlist,
@quiz
end
Thx.
Here is my code.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*. according the due date end user select and ALTER temp table
find the nomatch table in the occh and return the table
*/
ALTER PROCEDURE dbo.test2
@quiz VARCHAR( 25 ),
@debug bit = 0
as
DECLARE @sql nvarchar(4000),
@paramlist nvarchar(4000)
begin
CREATE TABLE #tmpTrained(
EmplID char(30))
set @sql='select distinct EmplNO from tblCurrentWinTrainingLog where 1=1'
set @sql= @sql+ ' AND quizname = @xquiz '
IF @Debug = 1
BEGIN
PRINT @sql PRINT ''
END
set @sql='Insert into #tmpTrained '+ @sql
exec (@sql)
set @sql='select * from #tmpTrained '
exec (@sql)
SELECT @paramlist = '@xquiz varchar(25)'
EXEC sp_executesql @sql, @paramlist,
@quiz
end
Thx.