close; 
sql.Clear; 
sql.Add('select case when intType=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' end  as inttype1 from test '); 
open; 
前天看了个帖子,代码如上,我跟着写了个测试代码,inttype是整数型的,怎么运行老是显示CASE查询表达式语法出错,请各位大老赐教,谢谢!

解决方案 »

  1.   

     with adoquery1 do
       begin
         close;
         sql.Clear ;
         sql.Add('select case when intType=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' end  as inttype1 from test ') ;
         open;
       end;创建的表的字段 intType 类型是 int  
    我测试可以的呀  
      

  2.   

    我的数据库是用ACCESS建立的,inttype设成整型的,就是会那个错误
      

  3.   

    哦 没用过ACCESS建数据库 我是用SQL2000
      

  4.   

    access中支持case写法吗,我不知道,但如果支持你可以把intType加上[],也许在access中是关键字
      

  5.   

    access是不支持case when 这个语句的,这个语句在access里应该用IIf(expr, truepart, falsepart)
      

  6.   

    ACCESS好像不支持这个吧,好像是用的iif还是什么。
      

  7.   


    Select iif(IsNull( express ), value1, value2 ) From TableNameiif(IsNull( express ), value1, value2 )
    相当于:
    If express Is Null Then
    Return value1
    Else
    Return value2
    End if
      

  8.   


    ' 我试没有问题,看一下是否你的代码问题'create table tb1(id varchar(20),a int )
    insert into tb1 values('1',1)
    insert into tb1 values('',1)
    insert into tb1(a) values(2)
    insert into tb1(a) values(3)select case when a=1 then 'ss' when a=2 then 'aa' end as sss  from tb1select * from tb1'1 1
    1
    NULL 2
    (所影响的行数为 3 行)'procedure TForm1.Button1Click(Sender: TObject);
    begin
    ADOQuery1.close;
    ADOQuery1.SQL.Clear ;
    ADOQuery1.SQL.Add('select case when a=1 then ''10'' when a=2 then ''20'' end as sss  from tb1');
    ADOQuery1.open;end;
      

  9.   

    Acess 不支持,你的语句SQL Server 支持