查询姓名是3个字的学生姓名select sname from student
where Sname like '___'这是三个下划线
按理说
执行结果应该是3个汉字的名字,为什么两个汉字的名字也有呢

解决方案 »

  1.   

    select sname from student
    where Sname like N'[吖-做][吖-做][吖-做]'这样查
      

  2.   

    select * from student where len(sname) = 3
    select * from student where len(cast(sname as varchar)) = 3
      

  3.   

    因为有空格的缘故
    where rtrim(ltrim(Sname))like '___'
      

  4.   

    where rtrim(ltrim(Sname))like '___'
      

  5.   

    select sname from student
    where Sname like N'[吖-咗][吖-咗][吖-咗]'改为这样,以前总结的一个错误,差点忘了http://blog.csdn.net/htl258/archive/2009/09/21/4571814.aspx
      

  6.   


    create table tb(name  nchar(3))
    insert into tb
    select '楼' union all
    select '楼主' union all
    select '楼主好'select * from tb where name like '___'--结果
    /*
    楼  
    楼主 
    楼主好
    */drop table tb;
    select * from tb
    create table tb(name  nvarchar(3))
    insert into tb
    select '楼' union all
    select '楼主' union all
    select '楼主好'select * from tb where name like '___'--结果
    /*
    楼主好
    */
      

  7.   

    select sname from student where len(sname) = 3