Use of STORED PROCEDURES in SQL

Use of STORED PROCEDURES in SQL:

(1) “STORED PROCEDURES” is a type of function in SQL Query which is used in other queries again and again. You can also pass parameters so that it gives results according to the given parameter.

(2) Syntax of “STORED PROCEDURE” statement is:

CREATE PROCEDURE PROCEDURE_NAME
AS
SQL STATEMENT
GO;

(3) Let’s take an example, Created Procedure to get the count of vendors according to the “City” column in Vendor Table.

(4) Select the database in the SQL server and click on the “New Query” button as shown.

Select the database in SQL server and click on the New Query

(5) After that new query editor open as shown.

SQL new query editor open

(6) After doing the above steps, write a query in the editor, as shown.

Stored Procedure Query

Source Code:

–// Creation of STORED PROCEDURE
Create Procedure __CountOfVendorInCity
Create Procedure
AS
Select Count(No_) AS [Vendor Count],City
from dbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972]
Group BY City
Order By Count(No_) Desc
Go
–// Creation of STORED PROCEDURE

(7) After writing the query, then execute the query (Shortcut keys is F5) as shown.

procedure created in sql

(8) After creation, the stored procedure shown in “Programmability”>Stored Procedure, as shown.

stored procedure shown in Programmability in sql

(9) Use this procedure in multiple queries.


Use of GROUP BY Statement in SQL
How to Take BACKUP from SQL Database
How to Fix WORK DATE issue in D365 BC
Use of REPEAT-UNTIL in Dynamics 365
Understanding the General Ledger and the COA– Microsoft

Leave a Reply