Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

tsql to Subtract two values

Posted on 2014-01-05
3
Medium Priority
?
376 Views
Last Modified: 2014-01-05
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
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 1200 total points
ID: 39757224
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
 

Author Comment

by:Dovberman
ID: 39757233
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
 

Author Closing Comment

by:Dovberman
ID: 39757234
Thank you.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question