см. Встроенные комментарии:
ALTER PROCEDURE dbo.GetCustomersDetails
(
@customerID nchar(5), --input parameter to stored procedure
@companyName nvarchar(40) output --output parameter to stored procedure, can be changed by the procedure and the value retrieved by the caller
)
AS
SELECT @companyName = CompanyName FROM Customers --set the output parameter as the last row from this query
WHERE CustomerID = @customerID --use the input parameter to filter the query
SELECT *
FROM Orders
WHERE CustomerID = @customerID --filter this query on the input parameter
ORDER BY OrderID
Вы можете объявлять локальные переменные, они не просто параметры хранимых процедур:
DECLARE @localVariable int --integer local variable
,@Another char(1) --multiple on one DECLARE
обычно @@ .... являются системными значениями, такими как @@ ROWCOUNT и @@ SPID, но вы можете делать такие сумасшедшие вещи, как:
DECLARE @@@@wtf int --this is valid, and works