A stored procedure is simply a combination of a bunch of SQL. Add some logic control in the middle.
Stored procedure running process
Create a stored procedure without parameters
-- create stored procedure
if (exists (select * from sys.objects where name = 'proc_get_student')) drop proc proc_get_student
create proc proc_get_student as select * from student;
result:
--call and execute stored procedure
exec proc_get_student;
search result:
Stored procedure with parameters
if (object_id('proc_find_stu', 'P') is not null)
drop proc proc_find_stu
go
create proc proc_find_stu(@startId int, @endId int)
as
select * from student where id between @startId and @endId
go
exec proc_find_stu 2, 4;
Results of the:
2018-05-08 15:50:54