مخزن جامع کدها و الگوهای توسعه

اسنیپت‌ها، ترفندها و کدهای کاربردی

مجموعه‌ای منتخب از ساختارهای کد، پیکربندی‌های بهینه، پیش‌نیازها و کدهای همراه برای زبان‌ها و فریم‌ورک‌های مختلف.

۱ کد انتخاب شده
دسته‌بندی: SQL Server Store Procedure
پاکسازی همه فیلترها
SQL Server SQL 1405/07/04

Store Procedure

sql
-- Stored Procedure
create proc SelectAll
As
begin
select * from Production.Product
end

exec SelectAll
--------------------
create proc GetProductByCategoryName
@CategoryName nvarchar(225) -- Value
as
begin
	select * from products
	inner join categories on products.CategoryID=categories.CategoryID
	where CategoryName=@CategoryName
end;

exec GetProductByCategoryName 'Condiments';
-----------------------------
create proc GetProductByCustomerId
@CustomerId int,
@CustomerCount int output
as
begin
	select @CustomerCount=count(*)  from orders
	where  CustomerID=@CustomerId
end;

declare @c1 int
exec GetProductByCustomerId 10,@c1 output
select @c1