--特殊处理会计凭证
INSERT INTO #BillIndex
SELECT DISTINCT
A.BillCode,
A.BillNumberId,
A.BillDate,
A.ETypeid,
A.DTypeId,
A.ktypeid,
L.BTypeid,
A.BillType,
L.Total,
L.NTotal,
0 AS totalinmoney,
0 AS ntotalinmoney,
C.Comment,
L.ATypeid,
A.TeamNo,
A.RedWord,
A.preferencemoney,
A.npreferencemoney,
A.ifmulaccount,
AC.fullname AS cfullname,
AC.rate
FROM BillIndex A
INNER JOIN ListTable L ON A.BillNumberID=L.BillNumberID and a.BillType=l.BillType
INNER JOIN AC_currency AC ON L.CID=AC.CID
INNER JOIN #stype S ON A.Stypeid=s.typeid
INNER JOIN #Dtype D ON D.typeid = A.DTypeId
INNER JOIN AC_Items ACI ON L.AtypeId=ACI.nid
INNER JOIN AccountCredence C ON C.BillNumberId = L.BillNumberID and C.ATypeID=L.BTypeID
WHERE A.BillType = 159
AND A.IfCheck = 't'
AND A.Draft = 0
AND ACI.UserCode IN (SELECT typeid FROM #atype1)
AND L.BTypeId = @BTypeId
AND A.BillDate>=@StartDate
AND A.BillDate<=@ENDDate
AND L.CID LIKE @CID
来源:https://www.cnblogs.com/gzjsrj/p/12298709.html