how to execute stored procedure code example
Example 1: create select stored procedure in sql server
CREATE PROCEDURE sp_getRaces
AS
BEGIN
SELECT * FROM dbo.Races
END ;
Example 2: create proc
IF OBJECT_ID ( 'Production.uspGetList', 'P' ) IS NOT NULL
DROP PROCEDURE Production.uspGetList;
GO
CREATE PROCEDURE Production.uspGetList @Product varchar(40)
, @MaxPrice money
, @ComparePrice money OUTPUT
, @ListPrice money OUT
AS
SET NOCOUNT ON;
SELECT p.[Name] AS Product, p.ListPrice AS 'List Price'
FROM Production.Product AS p
JOIN Production.ProductSubcategory AS s
ON p.ProductSubcategoryID = s.ProductSubcategoryID
WHERE s.[Name] LIKE @Product AND p.ListPrice < @MaxPrice;
SET @ListPrice = (SELECT MAX(p.ListPrice)
FROM Production.Product AS p
JOIN Production.ProductSubcategory AS s
ON p.ProductSubcategoryID = s.ProductSubcategoryID
WHERE s.[Name] LIKE @Product AND p.ListPrice < @MaxPrice);
SET @ComparePrice = @MaxPrice;
GO
Example 3: run stored procedure sql
call MY_SCHEMA.my_procedure();
exec MY_SCHEMA.my_procedure();
BEGIN
MY_SCHEMA.my_procedure();
END;