How To Create Stored Procedures with Parameters in MS SQL Server?
Submitted by: AdministratorVery often, you need to create a stored procedure with one or more parameters. You only supply values to those parameters at the time of executing the stored procedure.
Stored procedures with parameters can be created with the following syntax:
CREATE PROCEDURE procedure_name
@parameter_1 datatype,
@parameter_2 datatype,
...
@parameter_n datatype
AS
statement_1;
statement_2;
...
statement_n;
GO
The following tutorial exercise shows you how to create a stored procedure with one parameter called @url:
USE GlobalGuideLineDatabase;
GO
DROP PROCEDURE Hello;
GO
CREATE PROCEDURE Hello
@url nvarchar(40)
AS
PRINT 'Welcome to ' + @url;
GO
EXEC Hello 'globalguideline.com';
GO
Welcome to globalguideline.com
Submitted by: Administrator
Stored procedures with parameters can be created with the following syntax:
CREATE PROCEDURE procedure_name
@parameter_1 datatype,
@parameter_2 datatype,
...
@parameter_n datatype
AS
statement_1;
statement_2;
...
statement_n;
GO
The following tutorial exercise shows you how to create a stored procedure with one parameter called @url:
USE GlobalGuideLineDatabase;
GO
DROP PROCEDURE Hello;
GO
CREATE PROCEDURE Hello
@url nvarchar(40)
AS
PRINT 'Welcome to ' + @url;
GO
EXEC Hello 'globalguideline.com';
GO
Welcome to globalguideline.com
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Use Subqueries with the EXISTS Operators in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Get the Definition of a View Out of the SQL Server? |
☺ | How To Convert a Numeric Expression from One Data Type to Another? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |