Tuesday, 9 August 2016

SQL Server Stored Procedure with input parameter


Hello. Hope you are doing good. In this post we will learn how to create an SQL stored procedure with input parameter.

Consider following steps:


  1. Use create procedure command to create procedure like "create procedure abc"
  2. Define input parameter with @ to denote parameter values like '@Name varchar(15)', note that @Name is a parameter of type varchar with 15 character length. You can add multiple parameters by separating each with a comma (,)
  3. Write the SQL command you want the procedure to execute. For this example we will print name with today's date:

     create procedure showDateWithName 
     @Name varchar(15)
     as
     begin
     select 'Hello '+@Name +'! today is '+ convert(varchar,GETDATE(),106);
     end

  • To use the stored procedure run the execute command:
       execute showDateWithName 'Hasan'

Procedure Result

No comments:

Post a Comment