Reputation: 1945
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
Reputation: 1
grossamount-(grossamount*(discountpercentage/100)) as Discountpercentage
Upvotes: -1
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