已经开了很多帖子了,试验过无数遍,发现在sql里面没问题可是换成access数据库问题就多多了
string myselect = " select account.*,hte-glf +(case when (select Sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null then 0 else (select Sum(sr-zc) from [type] where [type].id=account.bianhao) end) as 余额from [account]";
不知道有没有解决的办法了,已经用了[]可是还是提示IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败。

解决方案 »

  1.   

    access中一些语法跟sql是不一样的
      

  2.   

    IIf 函数
     
    取决于表达式的计算结果,返回两部分之一。语法IIf(expr, truepart, falsepart)IIf 函数语法具有以下命名参数:部分 说明 
    expr 必选。要计算的表达式。 
    truepart 必选。在 expr 为 True 时返回的值或表达式。 
    falsepart 必选。在 expr 为 False 时返回的值或表达式。 
    说明IIf 总是同时计算 truepart 和 falsepart,即使只返回这两者之一。因此,应注意意外的副作用。例如,如果计算 falsepart 会导至除以零的错误,则即使 expr 为 True,也会发生错误。
      

  3.   

    "select accout.* ,hte-glf+ iif( select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null,0,select sum(sr-zc) from [type] where [type].id=account.bianhao) as ye from accout ";
    改了之后出现 语法错误。 在查询表达式 'select sum(sr-zc)' 中。
      

  4.   

    "select accout.* ,hte-glf+ iif(( select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null,0,(select sum(sr-zc) from [type] where [type].id=account.bianhao)) as ye from accout ";你 的iif是不是少了个括号
      

  5.   

    1.ACCESS中CASE改用IIF實現
    2.這裡判斷用ISNULL才對。
    tryselect accout.* ,hte-glf+ iif( isnull(select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) ,0,(select sum(sr-zc) from [type] where [type].id=account.bianhao)) as ye from accout
      

  6.   

    string myselect = "select accout.*,hte-glf + sum(iif (select bianhao from [type] where [type].bianhao=account.bianhao is not null,sr-zc,0 )) as ye frm account ";
    也是提示有语法错误 ,ye 是我要显示的字段,不用在数据表中建立吧
      

  7.   

    pinkyll() ( ) 信誉:100    Blog   加为好友  2007-07-13 14:35:30  得分: 0  
     
     
       string myselect = "select accout.*,hte-glf + sum(iif (select bianhao from [type] where [type].bianhao=account.bianhao is not null,sr-zc,0 )) as ye frm account ";
    也是提示有语法错误 ,ye 是我要显示的字段,不用在数据表中建立吧
      
     
    -----------------
    改為
    string myselect = "select accout.*,hte-glf + sum(iif (isNull(select bianhao from [type] where [type].bianhao=account.bianhao), 0, sr-zc)) as ye from account ";1.IIF的用法有問題
    2.from寫成了frm
      

  8.   

    to 一天到晚游泳的鱼 ,按你写的提示错误
    用于函数参数的个数不对 在查询表达式 'hte-glf+ iif( isnull(select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) ,0,(select sum(sr-zc) from [type] where [type].bianhao=account.bianhao))' 中。
      

  9.   

    lz的查询语句看着就觉得很有问题,把你的access数据库和要的结果发到我邮箱[email protected]我看看
      

  10.   

    select accout.*,hte-glf + sum(iif (isNull(select bianhao from [type] where [type].bianhao=account.bianhao), 0, sr-zc)) as ye from account 
    这个明显就有问题,hte-glf + sum(iif (isNull(select bianhao from [type] where [type].bianhao=account.bianhao), 0, sr-zc))  聚合函数sum这么可以跟hte-glf  这个+
      

  11.   

    select account.* , hte-glf+ iif( (select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null ,0,(select sum(sr-zc) from [type] where [type].bianhao=account.bianhao)) as ye from account這個可以isnull用的有問題,MS SQL和ACCESS還是有不少區別。PS:樓主的筆誤太多,一會是“accout”,一會是“account”。前面的關聯條件是“[type].bianhao=account.bianhao”,後面又是“[type].id=account.bianhao”。
      

  12.   

    select account.* , hte-glf+ iif( (select sum(sr-zc) from [type] where [type].bianhao=account.bianhao) is null ,0,(select sum(sr-zc) from [type] where [type].bianhao=account.bianhao)) as ye from account---------
    這個我做了測試了的,已經OK,並且修正了樓主的幾處筆誤。