我在下面創建的查詢,它在sql server 2012中工作良好,但在sql server 2008或2008R2中不起作用。請幫我解決這個問題。查詢在sql server 2012中可用,但在服務器2008中不可用
Select Batchno, BatchId, Transactiontype, LoanAccountNumber, TransactionId
, StaticDetailId, Name, Comment, BatchTotal
, case when Amount<0 then Amount*-1
Else Amount End as Amount
, ((BatchTotal) - (SUM(case when Amount<0 then Amount*-1 Else Amount End)
OVER(order BY Batchno ROWS BETWEEN 1000 Preceding and current row))) AS BatchBal
From (SELECT row_number() over (order by BO.BatchID) as [BatchNo]
, BO.BatchID, sd.TransactionType, tra.LoanAccountNumber, tra.TransactionID
, tra.StaticDetailID,tra.Name,tra.Comment, BO.BatchTotal,tra.Amount
FROM BackOfficeBatchTransactionDetails tra
join BackOfficeBatchDetails BO
on BO.BatchID=tra.BatchID and tra.isactive=1 and tra.isdeleted=0
join StaticDetails sd on sd.StaticDetailID=tra.StaticDetailID and sd.isactive=1
where BO.isactive=1 and BO.isdeleted=0 AND [email protected]
) AS G
的代碼在這種格式下是相當難讀的,但是我把這筆錢放在這個原因上:'1000之前的行和當前行之間的行'。如果我不是mi這個語法最近纔在SQ Server中引入。 – SchmitzIT 2014-09-18 19:17:15
是的這種語法是在sql server 2012中,這是它在2008年不工作的原因。請建議,以便它也可以在2008年。 – 2014-09-18 19:18:34