[@parameter [type_schema_name.] datatype
[VARYING] [= default] [OUT | OUTPUT | READONLY]
, @parameter [type_schema_name.] datatype
[VARYING] [= default] [OUT | OUTPUT | READONLY]]
[WITH {ENCRYPTION | RECOMPILE | RECOMPILE | EXECUTE AS Clause } ] EXECUTE AS Clause}]
[FOR REPLICATION]
AS
BEGIN
[declaration_section]
executable_section
END;
Parameters:
CREATE PROCEDURE spNhanvien
@nhanvien_name VARCHAR (50) OUT
AS
BEGIN
DECLARE @nhanvien_id INT;
SET @nhanvien_id = 8;
IF @nhanvien_id <10
SET @nhanvien_name = 'Smith';
ELSE
SET @nhanvien_name = 'Lawrence';
END;
The above procedure is named spNhanvien, there is a parameter of @nhanvien_name, the output of the parameter will be based on @nhanvien_id.
After that, you can perform the spNhanvien reference as follows:
USE [test]
GO
DECLARE @site_name varchar (50);
EXEC FindSite @site_name OUT;
PRINT @site_name;
GO
Once you've created the procedure successfully, there are also cases where you want to remove the procedure from the database for a few reasons.
To remove a procedure, we have the following syntax:
DROP PROCEDURE procedure_name ;
Parameters:
procedure_name: The name of the procedure you want to delete .
DROP PROCEDURE spNhanvien;
By executing this command, you have just deleted the spNhan procedure from the database.
Previous post: FUNCTION (Function) in SQL Server
Next lesson: IF . ELSE command in SQL Server