在一个表中按百分比select出记录条数
create procedure pro_topPercent
(
@ipercent [int] =0 --默认不返回
)
as
begin
select top (@ipercent ) percent * from books
end
或
create procedure pro_topPercent
(
@ipercent [int] =0
)
as
begin
select top((select COUNT (*) from books)*(@ipercent)/100) * from books
end
exec pro_topPercent '10' --执行存储过程
创建存储过程的语法类似带指针的C#,创建时参数表用小括号括起,输出参数带传递方向的参数标识 OUTPUT,输入参数不用,参数声明格式:
(
@studentname [nvarchar] (50) output
)
存储过程执行时参数表不用加括号,若有输出参数 先声明 用如下格式执行:
declare @studentname_1
exec myprocedure
'输入参数',@studentname_1 output, 如果前台用的是 .net的话可以在comand.parameters中添加传递方向为output的sqlparameter参数接收该值