- 当Update语句中的From表与Join表相同
* SQL
Sever : update t1
set
faccountid2=t2.faccountid from t_voucherentry t1 inner join
t_voucherentry t2 on t1.fvoucherid=t2.fvoucherid
where
t1.fdc=1 and t2.fdc=0 and
t1.fvoucherid= 0;
*
Sqlite
: update t_voucherentry set
faccountid2=t2.faccountid from t_voucherentry t1 inner join
t_voucherentry t2 on t1.fvoucherid=t2.fvoucherid where
t_voucherentry.fdc=1 and t2.fdc=0 and t_voucherentry.fvoucherid=
5;
Remark:SQL Server
from表用了别名后,语句中用到这个表的地方都必须用“别名”,诸如update后面和Where后面;
Sqlite
from表用了别名后,语句中用到这个表的地方都必须用“实名”,诸如update后面和Where后面;
- 当Update语句中的From表与Join表不相同
* SQL
Sever : UPDATE t_Balance
SET
FDebitFor = b.FDebitFor +
e.FDebitFor,
FCreditFor = b.FCreditFor +
e.FCreditFor,
FDebit = b.FDebit + e.FDebit,
FCredit = b.FCredit +
e.FCredit,
FYtdDebitFor = b.FYtdDebitFor +
e.FDebitFor,
FYtdCreditFor = b.FYtdCreditFor +
e.FCreditFor,
FYtdDebit = b.FYtdDebit +
e.FDebit,
FYtdCredit = b.FYtdCredit +
e.FCredit,
FEndBalanceFor = b.FEndBalanceFor +
e.FDebitFor-e.FCreditFor,
FEndBalance = b.FEndBalance + e.FDebit -
e.FCredit FROM t_Balance b INNER JOIN #Balance e ON b.FAccountID =
e.FAccountID AND b.fdetailid = e.fdetailid AND b.FCurrencyID =
e.FCurrencyID WHERE
b.FYear =
2022 AND
b.FPeriod =
12 ;
*
Sqlite
: UPDATE t_Balance
SET
FDebitFor = b.FDebitFor +
e.FDebitFor,
FCreditFor = b.FCreditFor +
e.FCreditFor,
FDebit = b.FDebit + e.FDebit,
FCredit = b.FCredit +
e.FCredit,
FYtdDebitFor = b.FYtdDebitFor +
e.FDebitFor,
FYtdCreditFor = b.FYtdCreditFor +
e.FCreditFor,
FYtdDebit = b.FYtdDebit +
e.FDebit,
FYtdCredit = b.FYtdCredit +
e.FCredit,
FEndBalanceFor = b.FEndBalanceFor +
e.FDebitFor-e.FCreditFor,
FEndBalance = b.FEndBalance + e.FDebit -
e.FCredit FROM t_Balance b INNER JOIN #Balance e ON b.FAccountID =
e.FAccountID AND b.fdetailid = e.fdetailid AND b.FCurrencyID =
e.FCurrencyID WHERE Balance.FYear = 2022 AND Balance.FPeriod = 12
;
Remark:SQL Server
from表用了别名后,语句中用到这个表的地方即可以用“实名”也可以用“别名”,类似update后面和Where后面;
Sqlite
from表用不用别名,语句中用到这个表的地方都必须用“实名”,诸如update后面和Where后面;
加载中,请稍候......