hi,
am tring to store the result of query in a variable using exec query string syntax. but i am not able to save this var value in a table because it is out of scope of exec environment. here is the code
SET @Query='DECLARE @TotRegistered as Int,@DateFrom as Datetime,@DateTo as Datetime;
set @DateFrom='+'''01/01/2010 00:00:00'''+' ;
set @DateTo='+'''01/07/2010 23:59:59'''+';
SELECT @TotRegistered=ISNULL(COUNT(*),0) FROM tb_StudentMaster WHERE Student_doj>=CONVERT(varchar(10),@DateFrom,121) AND Student_doj<=CONVERT(varchar(10),@DateTo,121);prin t @TotRegistered'
exec(@Query)
INSERT INTO tb_StudentAnalysis VALUES
('Total No of Students',@TotRegistered)
this code is printing the var value but its not inserting in table bcoz it is out of exec work environment. plzz help how to do this.