select * from tb where len(col)=2
seelct * from tb where datalength(col)=2看什么方式编码了。

解决方案 »

  1.   

    select * from table where len(ltrim(列名))=2
      

  2.   

    select * from table where len(ltrim(col))=2
      

  3.   

    declare @t table(test nvarchar(10))
    insert @t select 'A'
    select len(test) from @t
    select datalength(test) from @t
    declare @s table(test varchar(10))
    insert @s select 'A'
    select len(test) from @s
    select datalength(test) from @s
    /*----------- 
    1(所影响的行数为 1 行)            
    ----------- 
    2(所影响的行数为 1 行)
    (所影响的行数为 1 行)            
    ----------- 
    1(所影响的行数为 1 行)            
    ----------- 
    1(所影响的行数为 1 行)
    */
      

  4.   

    select name
    from tablename
    where len(name)=2