我想把数据库中的字段STATUS状态(有四中值A、B、C、D),是A的时候显示出来的是‘报废’
B‘好的’,C‘没用’,D‘在用’。应该怎样写SQL语句才能显示在DBGRID中。

解决方案 »

  1.   

    在sql语句中用case语法如:
      select mystatus= case status
                       when 'a' then ''
                       when 'b' then ''
      from tablename
      

  2.   

    在DBGrid的DrawDataCell写入:
    if Field.FieldName=status' then
    begin
      if q1.FieldValues['status']='A' then
       begin
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.Canvas.TextOut(Rect.left+1,Rect.top+1,'报废');
       end;
      if q1.FieldValues['status']='B' then
       begin
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.Canvas.TextOut(Rect.left+1,Rect.top+1,'好的');
       end;
      if q1.FieldValues['status']='C' then
       begin
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.Canvas.TextOut(Rect.left+1,Rect.top+1,'没用');
       end;
      if q1.FieldValues['status']='D' then
       begin
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.Canvas.TextOut(Rect.left+1,Rect.top+1,'在用');
       end;
    end;
      

  3.   

    在sql语句中用case语法如:
      select mystatus= case status
                       when 'a' then ''
                       when 'b' then ''
      from tablename这样不行哦
      

  4.   

    select ss = case  Ltrim(Rtrim(ss))
                   when 'A' then '报废'
                   when 'B' then '好的'
                   when 'C' then '有用'
                   when 'D' then '在用'
                end
    from table1