How to use Table Variable inside Dynamic Sql Query - Sql server

Mar 28, 2019 BY xtreme


create PROCEDURE [dbo].[report_admissions] @student_name varchar(100)='', @student_roll varchar(115)='' AS BEGIN DECLARE @Admissions TABLE ( ADMISSION_ID INT, ADMISSSION_DATE datetime
    )


	DECLARE @query varchar(MAX)
	SET @query ='select DISTINCT	admission_id, ADMISSSION_DATE FROM admissions'
    insert into @Admissions
	EXEC(@query)  

    select ADMISSION_ID,ADMISSSION_DATE FROM @ADMISSIONS

END



Related