简体   繁体   English

SQL:条件百分比增加

[英]SQL: Conditional Percentage Increase

Using Bartender custom SQL, I am attempting to add 20% to a label price if it is VAT applicable (ie if it has a tax ID of 2583) 使用Bartender自定义SQL,如果适用增值税,我尝试将标签价格增加20%(即,如果其税号为2583)

The information for tax is stored in one database table called StockItem.TaxCodeID, and the price is stored in another called StockItemPrice.Price. 税收信息存储在一个名为StockItem.TaxCodeID的数据库表中,而价格存储在另一个名为StockItemPrice.Price的数据库表中。

Is there a way to make this happen? 有没有办法做到这一点? I'm very new to SQL and have gotten by so far using the query and join tools included with bartender, and the code it generates makes logical sense to me. 我对SQL还是很陌生,到目前为止,已经使用了调酒师附带的查询和联接工具,它生成的代码对我来说是合乎逻辑的。

SELECT "dbo"."StockItem"."Code", "dbo"."StockItem"."Name", "dbo"."StockItem"."TaxCodeID", "dbo"."StockItem"."PartNumber", "StockItemPrice"."Price" FROM "dbo"."StockItem" , "StockItemPrice"
WHERE "dbo"."StockItem"."ItemID" = "StockItemPrice"."ItemID" 
AND 
   ("StockItemPrice"."PriceBandID" = 1001 
      AND "dbo"."StockItem"."Code" LIKE '6%' 
      AND "dbo"."StockItem"."PartNumber" LIKE '%?BarcodeSearch1%' 
      AND "dbo"."StockItem"."Name" LIKE '%?NameSearch%' 
      AND "dbo"."StockItem"."TaxCodeID" = 258

Sorry in advance if I haven't provided enough information, I'll do my best to add more if needed! 抱歉,如果我没有提供足够的信息,我会尽力添加更多必要的信息!

Use case when statement, 声明case whencase when

select *, CASE taxid
     WHEN taxid=2538 THEN price *1.20
     else price
END as newcolumn
from stockitem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM