Jac*_*aru 5 sql sql-server-2008
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'
Run Code Online (Sandbox Code Playgroud)
此查询返回此数据:
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
Run Code Online (Sandbox Code Playgroud)
我想在此查询中添加2列Vat 5%rate Amount = vat type id 2和Vat 15%rate Amount = vat Type id 4
我在这个查询中有这样的第二个查询我使用TableOrder id = 319
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
Run Code Online (Sandbox Code Playgroud)
输出:
Id Description VRate VatAmount
2 Food 5 8.8094
4 Cold drinks 15 7.143
Run Code Online (Sandbox Code Playgroud)
在此查询中,获取增值税5%用于增值税类型Id = 2和15%用于增值税类型Id = 4在上述数据中390 TableOrder Id显示总金额270和增值金额为(8.8094 + 7.143)
我希望此数量显示在列中的以下数据中
表关系是
在表BillItem表中我有Item Id和TableOrder Id
在Item表中我有VatTypeId