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

大家看看我这这储存过程是怎么回事
SQL code
ALTER PROC [dbo].[Getlist]
@RecNum varchar(10)='',
@UserName varchar(10)='',
@StartNum varchar(10)='',
@endNum varchar(10)='',
@Order varchar(10)='',
@return varchar(255)='' output
AS
declare @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 '
end
else
begin
    set @orderby= N' RegTime '
end
if (@RecNum!='')
begin
    set @W_YiQi='  AND recNum in ( '+@RecNum+' ) '
end 
else
begin
set @W_YiQi=''
end
if (@StartNum!='' and @endNum!='')
begin
     set @W_YiQi=' AND recNum >='+@StartNum+' AND recNum<= '+@endNum
end 
if (@UserName='')
begin
    set @endSqlStr=@selectForm+ ' WHERE id>0 '+@W_YiQi +' order by '+@orderby
END
ELSE
BEGIN
    set @endSqlStr=@selectForm+ ' WHERE UserName='''+@UserName+''' '+@W_YiQi +' order by '+@orderby
END
set @return =@endSqlStr


调用储存过程
SQL code
USE [regInfoData]
GO

DECLARE    @return_value int,
        @return varchar(255)

EXEC    @return_value = [dbo].[Getlist]
        @RecNum = N'65535',@Order= N'1',
        @return = @return OUTPUT

SELECT    @return as N'@return'

SELECT    'Return Value' = @return_value

GO


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

------解决方案--------------------
declare @orderby varchar(6)
改成
declare @orderby varchar(9)