MS SQL Server Concepts and Programming Question:

How To Execute a Stored Procedure in MS SQL Server?

MS SQL Server Interview Question
MS SQL Server Interview Question

Answer:

If you want execute a stored procedure created previously, you can use the EXECUTE statement in the following formats:

EXEC procedure_name;
EXECUTE procedure_name;

The key word EXEC is actually optional. So you can execute a stored procedure by just entering the procedure name as the statement. See examples in the following tutorial exercise:

USE GlobalGuideLineDatabase;
GO

-- create a quick procedure
CREATE PROCEDURE date AS
PRINT CONVERT(VARCHAR(20),GETDATE(),107);
GO

-- execute with EXEC
EXEC date;
GO
May 19, 2007

-- execute with EXEC
date;
GO
May 19, 2007


-- using a reserved keyword as procedure name
CREATE PROCEDURE datetime AS PRINT GETDATE();
GO

datetime;
GO
May 19, 2007 11:35PM

Looks like SQL Server allows you to reserved keywords as stored procedure names


Previous QuestionNext Question
How To Create a Simple Stored Procedure in MS SQL Server?How To List All Stored Procedures in the Current Database using MS SQL Server?