首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

大家看看小弟我这这储存过程是咋回事

2012-03-12 
大家看看我这这储存过程是怎么回事SQL codeALTER PROC [dbo].[Getlist]@RecNum varchar(10),@UserName

大家看看我这这储存过程是怎么回事

SQL code
ALTER PROC [dbo].[Getlist]@RecNum varchar(10)='',@UserName varchar(10)='',@StartNum varchar(10)='',@endNum varchar(10)='',@Order varchar(10)='',@return varchar(255)='' outputASdeclare @endSqlStr varchar(255)declare @SQL varchar(255)declare @selectForm varchar(255)declare @W_YiQi varchar(255)declare @orderby varchar(6)set @selectForm=N'select * from RegInfo'if(@Order='')begin    set @orderby=N' id 'endelsebegin    set @orderby= N' RegTime 'endif (@RecNum!='')begin    set @W_YiQi='  AND recNum in ( '+@RecNum+' ) 'end elsebeginset @W_YiQi=''endif (@StartNum!='' and @endNum!='')begin     set @W_YiQi=' AND recNum >='+@StartNum+' AND recNum<= '+@endNumend if (@UserName='')begin    set @endSqlStr=@selectForm+ ' WHERE id>0 '+@W_YiQi +' order by '+@orderbyENDELSEBEGIN    set @endSqlStr=@selectForm+ ' WHERE UserName='''+@UserName+''' '+@W_YiQi +' order by '+@orderbyENDset @return =@endSqlStr

调用储存过程
SQL code
USE [regInfoData]GODECLARE    @return_value int,        @return varchar(255)EXEC    @return_value = [dbo].[Getlist]        @RecNum = N'65535',@Order= N'1',        @return = @return OUTPUTSELECT    @return as N'@return'SELECT    'Return Value' = @return_valueGO

最后的查询语句是@return=select * from RegInfo WHERE id>0 AND recNum in ( 65535 ) order by RegTi
为什么RegTime 变成了RegTi

[解决办法]
declare @orderby varchar(6)
改成
declare @orderby varchar(9)

热点排行