Select
Id,
ROW_NUMBER() over(Order By(Select 1)) as SNo,
Tableno as 'Table Number',
convert(Date, tableorder.Date) as Date,
(LTRIM(RIGHT(CONVERT(VARCHAR(20), tableorder.Date, 100), 7))) as Time,
case
when TableOrder.Status = 1 then 'Open'
when TableOrder.Status = 0 then 'Close'
else 'Undifined'
end As 'Order Status',
KotNO as 'Kot Number',
(Select SUM(NetAmount)
from Bill
where Bill.OrderId = TableOrder.Id) as 'Total Amount'
from
TableOrder
Where
IsActive = '1' And IsDelete = '0'
このクエリは次のデータを返します。
Id SNo Table Number Date Time Order Status Kot Number Total Amount
318 1 1 4/3/2013 12:00AM Close 1218 270
319 2 1 4/3/2013 12:00AM Close 7581 335
320 3 1 4/3/2013 12:00AM Close 7582 110
321 4 1 4/3/2013 12:00AM Close 7585 165
323 5 4 4/3/2013 12:00AM Close 7586 80
324 6 1 4/3/2013 12:00AM Close 7587 45
325 7 3 4/3/2013 12:00AM Close 7588 150
326 8 1 4/3/2013 12:00AM Close 7589 145
327 9 1 4/3/2013 12:00AM Close 7590 70
328 10 4 4/3/2013 12:00AM Close 7591 120
Vat 5% rate Amount = vat type id 2 および Vat 15% rate Amount = vat Type id 4 のこのクエリに 2 つの列を追加したい
このクエリには、TableOrder id = 319 を使用するこのような 2 番目のクエリがあります。
Select
Vt.Id, Vt.Description,
abs(Vt.Rate) as VRate,
Sum((( ItemPrice * Qty) - NetAmount)) as VatAmount
from
BillItem1 as B1
Left JOIN
ItemDescription ItD ON ItD.Id = B1.itemId
Left Join
VatType Vt on Vt.Id = ItD.TaxId
where
B1.IsActive = 1 and B1.IsDelete = 0
and B1.OrderId = 319
Group By
Vt.Id, Vt.Rate, Vt.Description
Order By
SUM((ItemPrice*Qty) - NetAmount) DESC
出力:
Id Description VRate VatAmount
2 Food 5 8.8094
4 Cold drinks 15 7.143
このクエリでは、上記のデータ 390 の Vat タイプ Id = 2 の VAT 5% と VAT タイプ Id = 4 の 15 % を取得します。TableOrder Id は合計金額 270 を表示し、Vat 金額は (8.8094+7.143) です。
この金額を列のデータの下に表示したい
テーブル関係は
テーブルBillItemテーブルにはアイテムIDとテーブルオーダーIDがあり
ますアイテムテーブルにはVatTypeIdがあります