已经开了很多帖子了,试验过无数遍,发现在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) 而失败。
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) 而失败。
取决于表达式的计算结果,返回两部分之一。语法IIf(expr, truepart, falsepart)IIf 函数语法具有以下命名参数:部分 说明
expr 必选。要计算的表达式。
truepart 必选。在 expr 为 True 时返回的值或表达式。
falsepart 必选。在 expr 为 False 时返回的值或表达式。
说明IIf 总是同时计算 truepart 和 falsepart,即使只返回这两者之一。因此,应注意意外的副作用。例如,如果计算 falsepart 会导至除以零的错误,则即使 expr 为 True,也会发生错误。
改了之后出现 语法错误。 在查询表达式 'select sum(sr-zc)' 中。
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
也是提示有语法错误 ,ye 是我要显示的字段,不用在数据表中建立吧
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
用于函数参数的个数不对 在查询表达式 '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))' 中。
这个明显就有问题,hte-glf + sum(iif (isNull(select bianhao from [type] where [type].bianhao=account.bianhao), 0, sr-zc)) 聚合函数sum这么可以跟hte-glf 这个+
這個我做了測試了的,已經OK,並且修正了樓主的幾處筆誤。