Ingimar Andresson
Ingimar Andresson

Reputation: 1945

Calculate net amount after discount in formula

I need to put value in calculated column in SQL Server.

The formula will need to be something like: col1 * 0.col2 (both columns 1&2 can be null). Col1 is the GrossAmount(decimal(10,2) and Col2(smallint) is the percent discount.

I tried to search for a solution on this, but found nothing helpful so far. Any idea where I might find a good solution for this?

Upvotes: 0

Views: 12575

Answers (2)

madhu
madhu

Reputation: 1

grossamount-(grossamount*(discountpercentage/100)) as Discountpercentage

Upvotes: -1

HABO
HABO

Reputation: 15852

Are you looking for something like:

select GrossAmount, DiscountPercentage,
  GrossAmount * DiscountPercentage / 100.0 as [DiscountAmount]
  from YourTable

This assumes that DiscountPercentage is the amount to be discounted in percent. The discounted gross would then be:

GrossAmount * ( 100.0 - DiscountPercentage ) / 100.0 as [DiscountedGrossAmount]

In a table definition you could create a computed column thusly:

DiscountedGrossAmount as GrossAmount * ( 100.0 - DiscountPercentage ) / 100.0

Upvotes: 2

Related Questions