SELECT @Tax = SUM(QuoteItem.SalesPrice) * TOP (1) Tax.Amount
FROM Tax INNER JOIN
Job ON Tax.TaxId = Job.TaxId INNER JOIN
Quote ON Job.JobId = Quote.JobId INNER JOIN
QuoteItem INNER JOIN
Room ON QuoteItem.RoomId = Room.RoomId ON Quote.QuoteId = Room.QuoteId
WHERE (Room.QuoteId = @QuoteId) AND (QuoteItem.UnitId = @UnitId)
RETURN @Tax
結果:需要一個SQL查詢幫助
Msg 156, Level 15, State 1, Procedure fn_GetQuoteUnitTax, Line 54
Incorrect syntax near the keyword 'TOP'.
注意,當我忽略了TOP(1)它說:
Msg 8120, Level 16, State 1, Procedure fn_GetQuoteUnitTax, Line 54
Column 'Tax.Amount' is invalid in the select list because it is not contained in
either an aggregate function or the GROUP BY clause.
如果你告訴我們你是什麼這將有助於試圖完成。 – 2009-12-13 12:36:30
我想要做的事情很簡單,你可以從查詢中看到它,我想把所有的QuoteItems的SalesPrice都拿走,並且把它和Job的稅率相乘。 – Shimmy 2009-12-13 13:05:14
你爲什麼試圖在tax.amount字段上運行'TOP 1'?另外,你的SQL缺少'QUOTEITEM'連接標準。 – 2009-12-13 18:02:29