15,849,306 members
1.00/5 (1 vote)
See more:
C#
```public void SalePrice()
{
double originalPrice, discountPercentage, discountAmount, salePrice;
con.Open();
SqlCommand sqlcom = new SqlCommand("USP_SalePriceCalculation", con);
sqlcom.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
// Get item's original price.
originalPrice = double.Parse(dt.Rows[0]["actprice"].ToString());

// Get discount percentage.
discountPercentage = double.Parse(dt.Rows[0]["Discount"].ToString());

// Create decimal representation of %  (move point left two places)
discountPercentage = discountPercentage / 100;

// Calculate amount of the discount.
discountAmount = originalPrice * discountPercentage;

// Calculate sale price.
salePrice = originalPrice - discountAmount;

// Display sale price as Currency ("c")
lblPrice.Text = salePrice.ToString("c", Cultures.INDIA);
}
con.Close();
}
public static class Cultures
{
public static readonly CultureInfo INDIA =
CultureInfo.GetCultureInfo("en-IN");
}```

Now i want to Calcualate SubTotal Based on that SalePrice and Quantity(textbox)
Any one help me that how to calculate SubTotal?
Posted
deepankarbhatnagar 18-Sep-15 7:17am
Member 11878541 18-Sep-15 8:27am
SubTotal= Price after discount and quantity(that selected by customer)

Total =sum of all SubTotals
vagelis1 18-Sep-15 10:13am
And still price * qty doesn't answer you question???

## Solution 1

It is simple
C#
```SalePrice();
var unitPrice =  long.Parse(lblPrice.Text);
var qty = int.Parse(txbQty.Text);

var subTotal = unitPrice * qty;```

By salePrice() you have the discounted price that applies to all products. So subtotal is the sum of all totals.

v2

## Solution 2

Hi,

Why can't you implement the same in SQL Server,try below query to achieve the same in SQL server side.

SQL
```select sum(col) as SubTotal
from tablename
Group by Quantity, Price```