Create your SP(Stored procedure) In SP you can write your same select query and add parameter to the SP.in your frond end call the SP and pass the parameter for ex
create procedure [dbo].[USP_School_Details Select]
@Years varchar(10);
AS
BEGIN
schoolname, schoolid, count(studentid) as studenttotals,age,sex from student where left(studentid,4) = @Years
END
exec USP_School_Details Select '2007'