Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

tsql to Subtract two values

I have two selected values as follows:

Returns Price1
    (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2014-1-3'      
      AND SymbolID=11818)

Returns Price2  
     (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2013-12-30'      
      AND SymbolID=11818)

How do I SELECT Price1 - Price2?

     (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2014-1-3'      
      AND SymbolID=11818)
  -
     (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2013-12-30'      
      AND SymbolID=11818)

Incorrect syntax near '-'

Thank you
0
Dovberman
Asked:
Dovberman
  • 2
1 Solution
 
Rgonzo1971Commented:
Hi,

pls try

SELECT 

   (SELECT ClosePrice FROM StockHist 
      WHERE QuoteDate='2014-1-3'      
      AND SymbolID=11818)  as p1 
  -
     (SELECT ClosePrice FROM StockHist 
      WHERE QuoteDate='2013-12-30'       
      AND SymbolID=11818) as p2

Open in new window

Regards
0
 
DovbermanAuthor Commented:
Thanks for the ideas.

This worked:

SELECT
(
  (
   (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2014-1-3'      
      AND SymbolID=11818)  
      -
     (SELECT ClosePrice FROM StockHist
      WHERE QuoteDate='2013-12-30'      
      AND SymbolID=11818)
 
   )
 )  * 12 AS Answer
0
 
DovbermanAuthor Commented:
Thank you.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now