How To Provide Values to Stored Procedure Parameters in MS SQL Server?
Submitted by: AdministratorIf a stored procedure is created with parameters, you need pass values to those parameters when calling the stored procedure with one of two formats listed below:
-- Passing values only
EXEC procedure_name value_1, value_2, ... value_n;
-- Passing name-value pairs
EXEC procedure_name
@parameter_1 = value_1,
@parameter_2 = value_2,
...
@parameter_n = value_n;
The tutorial exercise below shows 2 ways to pass values to stored procedure parameters:
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
EXEC Hello @url='globalguideline.com';
GO
Welcome to globalguideline.com
Submitted by: Administrator
-- Passing values only
EXEC procedure_name value_1, value_2, ... value_n;
-- Passing name-value pairs
EXEC procedure_name
@parameter_1 = value_1,
@parameter_2 = value_2,
...
@parameter_n = value_n;
The tutorial exercise below shows 2 ways to pass values to stored procedure parameters:
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
EXEC Hello @url='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? |
☺ | What are system databases in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Use Subqueries with the EXISTS Operators in MS SQL Server? |
☺ | How To Get the Definition of a View Out of the SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |