select title from news 比如读取title字段的值,长度超过20就用“...”表示,用SQL语句怎么写啊

解决方案 »

  1.   

    select 
    case title
    when len(title)>20 then SUBSTRING(title,0,19)+'...'
    ELSE title
    END 
    form news
      

  2.   

    select (case title when len(title)>20 then substring(title,0,19)+'...' 
    ELSE title END) as title 
    form news 
      

  3.   

    1楼可以,另外,还可以写个公共的方法,截取指定长度的字符串并加...,然后再需要的地方调用。比如:public static string CutString(string input,int MaxLength)
    {
       if(input.Length>MaxLength)
       {
          return input.SubString(0,MaxLength)+"...";
       }
       else
       {
         return input;
       }
    }
      

  4.   

    大可不必这样 如果楼主要做web程序直接在css里设置样式就能达到这个效果
      

  5.   


    select (case when len(title)>20 then substring(title,0,19)+'...' 
    ELSE title END) as title 
    form news