SQL Server进阶(四)存储过程

新建存储过程

Create PROCEDURE [dbo].[p_test]
    @type int
AS
BEGIN
    declare @count int
    if(@type =1)
        begin
            select  @count = (select count(*) from dbo.UserGrowthDetail)
            print @count
            return @count
        end
    else if(@type =2)
        begin
            select  @count = (select count(*) from dbo.UserGrowthValue)
            print @count
            return @count
        end
END

执行存储过程

GO

DECLARE    @return_value int

EXEC    @return_value = [dbo].[p_test]
        @type = 1

SELECT    Return Value = @return_value

GO