Create a stored procedure
Alter PROCEDURE Zmt_firstpro
@condition nvarchar (1000)
As
Begin
--set NOCOUNT ON declare
@strsql nvarchar (1000)
Set @strsql = ' Select username from trainstudents ' [email protected]
Print (@strsql)
EXEC (@strsql)
End
exec Zmt_firstpro ' where age >8 '
--//Creating a temporary table 1
Alter PROCEDURE Zmt_firstpro
As
Begin
SET NOCOUNT ON select * to #zmt_student from trainstudents
SELECT * FROM #zmt_student
drop table #zmt_student
End
EXEC Zmt_firstpro
Creating a temporary Table 2
Alter PROCEDURE Zmt_firstpro
As
Begin
SET NOCOUNT ON
CREATE TABLE #zmt_student (ID int)
INSERT INTO #zmt_student
Select ID from trainstudents
SELECT * FROM #zmt_student
drop table #zmt_student
End
EXEC Zmt_firstpro
Creating a temporary Table 3
Alter PROCEDURE Zmt_firstpro
@condition nvarchar (1000)
As
Begin
SET NOCOUNT ON
declare @strsql nvarchar (1000)
CREATE TABLE #zmt_student (ID int)
Set @strsql = ' INSERT into #zmt_student ' [email protected]+ ' from trainstudents '
Print (@strsql)
EXEC (@strsql)
SELECT * FROM #zmt_student
drop table #zmt_student
End
EXEC zmt_firstpro ' select id '
Database Operations (vii) Stored procedures