MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 25th, 2004, 10:09 AM
sn1p3t sn1p3t is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 14 sn1p3t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old June 25th, 2004, 12:48 PM
mikahjay mikahjay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Near Milwaukee, WI
Posts: 17 mikahjay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to mikahjay
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

Reply With Quote
  #3  
Old June 25th, 2004, 01:16 PM
sn1p3t sn1p3t is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 14 sn1p3t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This example is a lot more simplified than my real problem. In reality I need both values. Also, the second one doesn't work

Reply With Quote
  #4  
Old June 25th, 2004, 01:49 PM
mikahjay mikahjay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Near Milwaukee, WI
Posts: 17 mikahjay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to mikahjay
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

Reply With Quote
  #5  
Old June 26th, 2004, 06:19 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
Code:
select (tblTest.Quantity * tblTest.Price) as SubTotal
     , (tblTest.Quantity * tblTest.Price) * 1.06 as Total
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Use calculated field in same query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT