|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Use calculated field in same query
Right now I have one view that grabs records and sums up related records etc.... and returns a result. So basically it has the ID number and the number I calculated. THen I have another view that takes that number and performs calculations on it into three different columns. Is there any way to make these two view into one without a lot of repetative statements? Here is an example:
SELECT (tblTest.Quantity * tblTest.Price) as SubTotal, SubTotal * 1.06 as Total Obviously that doesn't work, but what could I do to get that basic thing to work? Thanks! |
|
#2
|
|||
|
|||
|
What's wrong with:
SELECT ((tblTest.Quantity * tblTest.Price) * 1.06) as Total or even SELECT ((tblTest.Quantity * tblTest.Price) as SubTotal) * 1.06 as SubTotal) ?? I'm not sure if the second way compiles, but there's absolutely nothing wrong with the first. Hope this helps... -Mikah |
|
#3
|
|||
|
|||
|
This example is a lot more simplified than my real problem. In reality I need both values. Also, the second one doesn't work
![]() |
|
#4
|
|||
|
|||
|
hmmm... rough. This is a problem. I'd give up quick and say you need two statements:
SELECT ((tblTest.Quantity * tblTest.Price) as SubTotal) and then SELECT ((SubTotal * 1.06) as Total) I would assume you know this already though. Sorry I can't help... -Mikah ![]() |
|
#5
|
||||
|
||||
|
Code:
select (tblTest.Quantity * tblTest.Price) as SubTotal
, (tblTest.Quantity * tblTest.Price) * 1.06 as Total
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Use calculated field in same query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|