2009-09-29 83 views
0

我使用以下select語句創建了一個視圖。在計算列中獲取增值稅金額

正如你所看到的,我給很多列設置了別名,使它更加友好。

我需要在本月底也就是「GrandTotal」,基本上小計+增值稅(這個增值稅欄顯示爲一個百分比,因此需要%添加到此)

感謝返回列你的幫助。

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

嘗試char(VAT) || '%' AS VATPercent,

0

我不知道該舍入是否正確(增值稅是否本輪下跌或最近一分錢?),但你的意思是這樣的:

ROUND((1+VAT/100) * ROUND([Unit Cost (LCY)] * [Qty_ to Receive], 2),2) AS GrandTotal 
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