SP定義與返回參數需要返回參數的存儲過程
if OBJECT_ID('CountSeatleEmployee') is not null
drop proc CountSeatleEmployee
go
CREATE PROC CountSeatleEmployee
AS
DECLARE @Total int
SELECT @Total =Count(*)
from [AdventureWorks2012].[Person].[Person] P
WHERE P.EMAILPROMOTION =0
RETURN @Total
--Execute SP
declare @Count int
exec @Count = CountSeatleEmployee
SELECT @COUNT
--11158 Records
--same SP without Return Parameter
if OBJECT_ID('CountSeatleEmployee') is not null
drop proc CountSeatleEmployee
go
CREATE PROC CountSeatleEmployee
AS
SELECT Count(*)
from [AdventureWorks2012].[Person].[Person] P
WHERE P.EMAILPROMOTION =0
exec CountSeatleEmployee'
現在爲什麼不直接使用以下。這兩個提供相同的輸出。爲什麼我們種子返回參數