当前位置:Gxlcms > 数据库问题 > sqlserver的存储过程

sqlserver的存储过程

时间:2021-07-01 10:21:17 帮助过:42人阅读

custom go if exists (select * from sys.objects where name=get_emp_count) begin drop procedure get_emp_count end go create procedure dbo.get_emp_count @age int, @count int output as begin --为on时结果中不返回受影响的行数,提高查询效率,只在改批处理域中生效。 set nocount on; select @count=count(*) from emp where age=@age select * from emp end go

create procedure语句必须是批处理的第一句,所以必须加go。

调用:

--测试
declare @result_count int
--调用带返回参数的存储过程时,参数后面要加output
--execute get_emp_count @age=22,@count=@result_count output
execute get_emp_count 22,@result_count output
--select @result_count as count
select count=@result_count

--打印该变量
print @result_count
go

 

sqlserver的存储过程

标签:保存   compile   语法   提升   where   网络通信   t-sql   te pro   sys   

人气教程排行