日期:2014-05-18  浏览次数:20571 次

关于存储过程的一个输入参数问题
create   procedure   getuseasset_one_month_rs
@btime   datetime,
@etime   datetime,
@ids   int,
@count   int
as
select         top   @count             names,zcname,onemoney,times   from   useasset   where   times   between   @btime   and   @etime   and   ids=@ids   order   by   times   desc
go
想把   top   10     后面的数改为输入参数传,可编译不过,是那里错了呢?

------解决方案--------------------
改正一下

alter procedure getuseasset_one_month_rs
@btime datetime,
@etime datetime,
@ids int,
@count int
as
declare @sql varchar(8000)
set @sql= '
select top '+rtrim(@count)+ ' names,zcname,onemoney,times from useasset where convert(char(10),times,120) between ' ' '+convert(char(10),@btime,120)+ ' ' ' and ' ' '+convert(char(10),@etime,120)+ ' ' ' and ids= '+rtrim(@ids)+ ' order by times desc '
print(@sql)
go