标签:
--无参数存储过程创建和调用
--创建存储过程usp_test user go if exists(select * from sysobjects where name=‘usp_test‘) drop proc usp_test go create proc usp_test as select * from test go --执行存储过程 exec usp_test go
--有参存储过程创建和调用
--创建存储过程
user test
if exists (select * from sysobjects where name=‘usp_test‘)
drop proc usp_test
go
create proc usp_test
@name varchar(32),
@age int = null
as
if @age is null
begin
select * from test where name = @name
end
else
begin
select * from test where name = @name and age = @age
end
go
--调用存储过程
exec usp_test @name=‘username‘
go
--有参数、输出存储过程和调用 --统计某年龄的人数 --创建存储过程 use test if exists (select * from sysobjects where name=‘usp_test‘) drop proc usp_test go create proc usp_test @age varchar(32), @count int output as set @count = (select count(1) from test where age = @age) go --执行存储过程 declare @age varchar(32) declare @count int set @age = ‘26‘ exec usp_test @age ,@count output print @count go
标签:
原文地址:http://www.cnblogs.com/Lv2014/p/5832617.html