我使用以下select语句创建了一个视图。
正如你所看到的,我已经使很多列混淆,以使它更加友好。
我需要在此末尾返回一个“GrandTotal”列,基本上是SubTotal + VAT(此增值税列显示为百分比,因此需要向此添加%)
感谢您的帮助。
SELECT
No_ AS CroCode,
Description,
[Vendor Item No_] AS SupplierStockCode,
[Qty_to Receive] AS Qty,
[Unit Cost (LCY)] AS UnitPrice,
[VAT %] AS VATPercent,
ROUND([Unit Cost (LCY)] * [Qty_ to Receive], 2) AS SubTotal
FROM
dbo.TableNameGoesHere
答案 0 :(得分:0)
尝试char(VAT) || '%' AS VATPercent,
答案 1 :(得分:0)
我不确定这种四舍五入是否正确(增值税四舍五入或最近的便士?),但你的意思是:
ROUND((1+VAT/100) * ROUND([Unit Cost (LCY)] * [Qty_ to Receive], 2),2) AS GrandTotal
答案 2 :(得分:0)
这会有效吗
Declare @TableNameGoesHere Table
(
[No_] VarChar (30),
Description VarChar (30),
[Vendor Item No_] VarChar (30),
[Qty_ to Receive] int,
[Unit Cost (LCY)] float,
[VAT %] float
)
Insert into @TableNameGoesHere Values ('1x', '1or3m Ipsum', '231234sxsd', 12, 23.36, 3.3)
Insert into @TableNameGoesHere Values ('2y', '2or43 Ipsum', '23vbswsxsd', 23, 13.86, 3.3)
Insert into @TableNameGoesHere Values ('3h', '3or46 Ipsum', 'asdf757xsd', 13, 43.55, 3.3)
Insert into @TableNameGoesHere Values ('4r', '4or6m Ipsum', '908msn2341', 22, 73.12, 3.3)
SELECT
No_ AS CroCode,
Description,
[Vendor Item No_] AS SupplierStockCode,
[Qty_ to Receive] AS Qty,
[Unit Cost (LCY)] AS UnitPrice,
[VAT %] AS VATPercent,
ROUND([Unit Cost (LCY)] * [Qty_ to Receive], 2) AS SubTotal,
Convert (VarChar, [VAT %] * ROUND([Unit Cost (LCY)]/100 * [Qty_ to Receive], 2) + ROUND([Unit Cost (LCY)] * [Qty_ to Receive], 2) ) + ' %' AS GrandTotal
FROM
@TableNameGoesHere