ALTER PROCEDURE [dbo].[USP_UBSLog_GetAllBySort]
 (
@field varchar(50),  --表字段名
@direction varchar(50), --排序方向
@logType  varchar(50)  --类型
 )
AS declare @strSQL   varchar(6000)       -- 主语句if @logType != ''
begin
set @strSQL = ' select * from UBSLog where  LogType  = ' + @field +
             ' order by [' + @field +'] ' + @direction  -- 这句有问题 不知道哪出错了end
else  //@logType 为空时可以查出信息
begin
set @strSQL = ' select * from UBSLog ' +
             ' order by [' + @field +'] ' + @direction
endexec (@strSQL)
GO

解决方案 »

  1.   

    @field 参数传入的是 UBSLog 表中的字段名?
      

  2.   

    alter PROCEDURE [dbo].[USP_UBSLog_GetAllBySort]
     (
    @field varchar(50),  --表字段名
    @direction varchar(50), --排序方向
    @logType  varchar(50)  --类型
     )
    AS declare @strSQL   varchar(6000)       -- 主语句if @logType != ''
    begin
    set @strSQL = ' select * from UBSLog where  LogType  = ''' + @field +
                 ''' order by [' + @field +'] ' + @direction  -- 这句有问题 不知道哪出错了end
    else  --@logType 为空时可以查出信息
    begin
    set @strSQL = ' select * from UBSLog ' +
                 ' order by [' + @field +'] ' + @direction
    endexec (@strSQL)GO
      

  3.   

    print @strSQL 出来是什么啊?
      

  4.   

    wgsasd311(自强不息) 的不行回 libin_ftsafe(子陌红尘)  @field 参数传入的是 UBSLog 表中的字段名print @strSQL :select * from UBSLog where  LogType  = 'IPAddress' order by [IPAddress] ASC参数 :@field = IPAddress @direction  = ASC  @logType  = Applacation
      

  5.   

    set @strSQL = ' select * from UBSLog where  LogType  = ' + @field +
                 ' order by [' + @field +'] ' + @direction  --  
    改成
    set @strSQL = ' select * from UBSLog where  LogType  = ' + @logType +   赋错值了
                 ' order by [' + @field +'] ' + @direction  
     
    谢谢:(
      

  6.   

    set @strSQL = ' select * from UBSLog where  LogType  = ' + @field +
                 ' order by [' + @field +'] ' + @direction  --  
    改成
    set @strSQL = ' select * from UBSLog where  LogType  = ' + @logType +   赋错值了
                 ' order by [' + @field +'] ' + @direction  ======请看我上面语句