存储过程中的top+变量(downmoon)
存储过程中的top+变量(downmoon) .lineBorderBlue1 { BORDER-TOP: #999999 1px groove; BORDER-BOTTOM: #999999 1px groove;BORDER-LEFT: #999999 1px groove; BORDER-RIGHT: #999999 1px groove; background-color:#efefef;} 存储过程中的TOP后跟一个变量会如何?
Create proc getWorkPlan2
@intCounter int
,@lngUserID int
as
select Top 5 lngWorkID,strWorkName,strExecHumanName,strBeginDate
from worklist where lngExecHumanID= @lngUserID
order by lngWorkID desc
现在想将这里的Top5 改为变量· Top @intCounter
如下
ALTER proc getWorkPlan2
@intCounter int
,@lngUserID int
as
exec ('select Top '+convert(varchar(10),@intCounter)+' lngWorkID,strWorkName,strExecHumanName,strBeginDate from worklist where lngExecHumanID= '
+convert(varchar(10),@lngUserID) +' order by lngWorkID desc '
老是提示在关键字 'convert' 附近有语法错误。
于是改为
ALTER proc getWorkPlan2
@intCounter int
,@lngUserID int
as
declare @strCounter varchar(10)
set @strCounter=convert(varchar(10),@intCounter)
declare @strUserID varchar(10)
set @strUserID=convert(varchar(10),@lngUserID)
exec ('select Top '+@strCounter+' lngWorkID,strWorkName,strExecHumanName,strBeginDate from worklist where lngExecHumanID= '
+@strUserID +' order by lngWorkID desc '
)
OK!