select @col_name from Customer where (@col_name)<>lTrim(rtrim(@col_name))改为:
select @col_name from Customer where len(@col_name)<>len(lTrim(rtrim(@col_name)))

解决方案 »

  1.   

    exec('select '+@col_name+' from Customer where len('+@col_name+')<>len(lTrim(rtrim(@col_name)))')
      

  2.   

    --晕,自己一点脑袋都不用啊?declare cur_Customer cursor for
    select column_name from information_schema.columns where table_name='Customer' and data_type='varchar'
    open cur_Customer
    declare @col_name varchar(100)
    fetch next from cur_Customer into @col_name
    while @@fetch_status=0
    begin
      exec('select '+@col_name+' from Customer where ('+@col_name+')<>lTrim(rtrim('+@col_name+'))')
      fetch next from cur_Customer into @col_name
    end
    close cur_Customer
    deallocate cur_Customer