解决方案 »

  1.   

    len函数返回的是数值,不是字符串
      

  2.   

    另外你的case when写法也有问题,不能直接这样写
      

  3.   

    还是一样的。报“关键字‘CASE’附近有语法错误”
      

  4.   

    我猜一下你的意图case len(@propertyno)
      when '1' then @propertyno = 'XX00000+'@propertyno
      when '2' then @propertyno = 'XX0000+'@propertyno
      when '3' then @propertyno = 'XX000+'@propertyno
      when '4' then @propertyno = 'XX00+'@propertyno
      when '5' then @propertyno = 'XX0+'@propertyno
      when '6' then @propertyno = 'XX+'@propertyno
    else 
      print 'propertyno数据出错'
    end 这段,改成
    SELECT @propertyno=
    case len(@propertyno)
      when '1' then  'XX00000+'@propertyno
      when '2' then 'XX0000+'@propertyno
      when '3' then  'XX000+'@propertyno
      when '4' then  'XX00+'@propertyno
      when '5' then 'XX0+'@propertyno
      when '6' then  'XX+'@propertyno
    else 
      print 'propertyno数据出错'
    end 
      

  5.   

    下面的语句是有问题的,sql server的t-sql不支持case 选择结构,case 语句只能在一个sql语句中使用的

    case len(@propertyno)
      when '1' then @propertyno = 'XX00000+'@propertyno
      when '2' then @propertyno = 'XX0000+'@propertyno
      when '3' then @propertyno = 'XX000+'@propertyno
      when '4' then @propertyno = 'XX00+'@propertyno
      when '5' then @propertyno = 'XX0+'@propertyno
      when '6' then @propertyno = 'XX+'@propertyno
    else 
      print 'propertyno数据出错'
    end
     
    是有问题的
      

  6.   

    SELECT @propertyno=
    case len(@propertyno)
      when '1' then  'XX00000+'@propertyno
      when '2' then 'XX0000+'@propertyno
      when '3' then  'XX000+'@propertyno
      when '4' then  'XX00+'@propertyno
      when '5' then 'XX0+'@propertyno
      when '6' then  'XX+'@propertyno
    else 
      set @propertyno='propertyno数据出错'
    end 
      

  7.   

    try  this,declare @propertyno char(50)
    declare @prno intselect @propertyno=max(propertyno) 
     from property 
     where propertyno like 'hg%'
     
    select @propertyno=dbo.F_Get_no(@propertyno)+1select @propertyno=
    case len(@propertyno)
      when 1 then 'XX00000+'@propertyno
      when 2 then 'XX0000+'@propertyno
      when 3 then 'XX000+'@propertyno
      when 4 then 'XX00+'@propertyno
      when 5 then 'XX0+'@propertyno
      when 6 then 'XX+'@propertyno
    else 
      'propertyno数据出错'
    endprint @propertyno
      

  8.   

    改成这样试试:
    declare @propertyno char (10)
    declare @prno int(3)
    select @propertyno=max(propertyno) from property where propertyno like 'hg%'
    SELECT @propertyno = dbo.F_Get_no(@propertyno)+1
     
    select @propertyno = case len(@propertyno) 
      when '1' then  'XX00000+'@propertyno
      when '2' then  'XX0000+'@propertyno
      when '3' then  'XX000+'@propertyno
      when '4' then  'XX00+'@propertyno
      when '5' then  'XX0+'@propertyno
      when '6' then  'XX+'@propertyno
    else  'propertyno数据出错'
    endprint @propertyno
      

  9.   

    我试了下,改成这样会报两处错误,第一处:SELECT @property=  报“=”附近语法错误。
    第二处:‘end ’附近有语法错误。 如果去掉“=”第一处错误还是报"关键字‘CASE’附近有语法错误”
      

  10.   

    我用的是SQL2005。上面说的几种方法,均会报错。