sql2000中:
如何查询A0这个字段长度是34位的数据集 A0是这样定义的:A0 VARCHAR(34)
A0有16位的,也有20位的数据单靠SQL能否可行?不行的话,我就只能用工具了

解决方案 »

  1.   

    ??Select * From TableName Where Len(A0)=34
      

  2.   

    可以呀, 
    declare @re varchar(34)
    select @re=A0 from <table>
      

  3.   

    是不是這個意思??
    Create Table A(A0 Varchar(5))
    Insert A Select 'AAAAA'
    Union All Select 'BB'
    Union All Select 'CCC'
    Union All Select 'DDDDD'
    GO
    Select * From A Where Len(A0)=5
    GO
    Drop Table A
    /*
    A0
    AAAAA
    DDDDD
    */
      

  4.   

    select * from table 
    where len(isnull(A0,'')) = 34这样就可以啊
      

  5.   

    如果创建表的时候没有ansi_padding on,出现的空格是不是都没办法计算在字符串的长度内?
      

  6.   

    len(isnull(A0,'')) 這個判斷沒有必要加
      

  7.   

    Select * From TableName Where datalength(A0)=34
      

  8.   

    Create Table A(A0 Varchar(5))
    Insert A Select 'AAAAA'
    Union All Select 'BB'
    Union All Select 'CCC'
    Union All Select 'DDDDD'
    Union All Select Null
    GO
    Select * From A Where Len(A0)=5
    Select * From A Where DataLength(A0)=5
    GO
    Drop Table A
    /*
    A0
    AAAAA
    DDDDD
    */具體是第一個還是第二個,你自己取捨吧。不過感覺上應該不是第二個,所以之前沒寫出來。
      

  9.   

    谢谢 paoluo(一天到晚游泳的鱼)