본문 바로가기

Database/MS-SQL

CREATE PROCEDURE !! DECLARE !! EXEC !! OUTPUT !!

반응형
CREATE PROCEDURE TotalSales 
@year smallint , @total money OUTPUT AS SELECT @total=SUM(Amount) FROM Orders WHERE DATEPART(yy,OrderDate) = @year RETURN @@ERRPR


======================================================
DECLARE @err int , @sum money 
EXEC @err = TotalSales , @year = 2001 , @total = @sum 
OUTPUT
IF @err = 0 PRINT "Total is " + STR (@sum) 
ELSE PRINT "Error occurred"