Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Need help with constructing one query statement [modified]

Need help with constructing one query statement [modified]

Scheduled Pinned Locked Moved Database
helpdatabasequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James Shao
    wrote on last edited by
    #1

    Hi, I am trying to construct a query statement that allows me to retrieve what’s known as “Bullish Divergence” in stock investing signals. It occurs when stock price reaches to a new high level, surpassing a previous price peak, while a certain strength indicator on the same date fails to surpass the strength indicator of the previous peak. This would suggest the stock price is over-valued. The logic is to first find all the stocks whose prices have reached new highs on 11/24/2009 within the past 10 days, and if their RSI figures fail to be greater than the RSI figures of the previous peaks, then we have a bullish divergence. :) I currently have the following query statement, which returns an error message saying “Subquery returned more than 1 value and cannot be used when subquery follows <, >, >=, <=, =”. Could anyone please help me with this? X| I would be very thankful as I’ve spent hours trying to get it to work. Thanks!!

    SELECT Date, Ticker, Price, RSI
    FROM Table
    WHERE (Price =
    (SELECT MAX(Price) AS Expr1
    FROM Table AS t2
    WHERE (Table.Ticker = Ticker) AND (Date BETWEEN DATEADD(day, - 10, '11/24/2009')
    AND '11/24/2009'))) AND (Date = '11/24/2009') AND
    (RSI <
    (SELECT RSI
    FROM Table AS t3
    WHERE (Price =
    (SELECT MAX(Price) AS Expr1
    FROM Table AS t4
    WHERE (t3.Ticker = Ticker) AND (Date BETWEEN DATEADD(day,
    -10, '11/23/2009') AND '11/23/2009')))))

    modified on Tuesday, December 29, 2009 8:38 PM

    B J 2 Replies Last reply
    0
    • J James Shao

      Hi, I am trying to construct a query statement that allows me to retrieve what’s known as “Bullish Divergence” in stock investing signals. It occurs when stock price reaches to a new high level, surpassing a previous price peak, while a certain strength indicator on the same date fails to surpass the strength indicator of the previous peak. This would suggest the stock price is over-valued. The logic is to first find all the stocks whose prices have reached new highs on 11/24/2009 within the past 10 days, and if their RSI figures fail to be greater than the RSI figures of the previous peaks, then we have a bullish divergence. :) I currently have the following query statement, which returns an error message saying “Subquery returned more than 1 value and cannot be used when subquery follows <, >, >=, <=, =”. Could anyone please help me with this? X| I would be very thankful as I’ve spent hours trying to get it to work. Thanks!!

      SELECT Date, Ticker, Price, RSI
      FROM Table
      WHERE (Price =
      (SELECT MAX(Price) AS Expr1
      FROM Table AS t2
      WHERE (Table.Ticker = Ticker) AND (Date BETWEEN DATEADD(day, - 10, '11/24/2009')
      AND '11/24/2009'))) AND (Date = '11/24/2009') AND
      (RSI <
      (SELECT RSI
      FROM Table AS t3
      WHERE (Price =
      (SELECT MAX(Price) AS Expr1
      FROM Table AS t4
      WHERE (t3.Ticker = Ticker) AND (Date BETWEEN DATEADD(day,
      -10, '11/23/2009') AND '11/23/2009')))))

      modified on Tuesday, December 29, 2009 8:38 PM

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      You are trying to get value with subquery which return more then one row and that is why you get error,but to solve this try to use TOP 1 or post your query to see where is problem.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      J 1 Reply Last reply
      0
      • B Blue_Boy

        You are trying to get value with subquery which return more then one row and that is why you get error,but to solve this try to use TOP 1 or post your query to see where is problem.


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        J Offline
        J Offline
        James Shao
        wrote on last edited by
        #3

        Unfortunately I was not able to post my query without failing to submit a new thread/post, not sure why. That's why I've post my query in another forum and I've put a link in the first post. Could you please help me out? Thanks!!

        1 Reply Last reply
        0
        • J James Shao

          Hi, I am trying to construct a query statement that allows me to retrieve what’s known as “Bullish Divergence” in stock investing signals. It occurs when stock price reaches to a new high level, surpassing a previous price peak, while a certain strength indicator on the same date fails to surpass the strength indicator of the previous peak. This would suggest the stock price is over-valued. The logic is to first find all the stocks whose prices have reached new highs on 11/24/2009 within the past 10 days, and if their RSI figures fail to be greater than the RSI figures of the previous peaks, then we have a bullish divergence. :) I currently have the following query statement, which returns an error message saying “Subquery returned more than 1 value and cannot be used when subquery follows <, >, >=, <=, =”. Could anyone please help me with this? X| I would be very thankful as I’ve spent hours trying to get it to work. Thanks!!

          SELECT Date, Ticker, Price, RSI
          FROM Table
          WHERE (Price =
          (SELECT MAX(Price) AS Expr1
          FROM Table AS t2
          WHERE (Table.Ticker = Ticker) AND (Date BETWEEN DATEADD(day, - 10, '11/24/2009')
          AND '11/24/2009'))) AND (Date = '11/24/2009') AND
          (RSI <
          (SELECT RSI
          FROM Table AS t3
          WHERE (Price =
          (SELECT MAX(Price) AS Expr1
          FROM Table AS t4
          WHERE (t3.Ticker = Ticker) AND (Date BETWEEN DATEADD(day,
          -10, '11/23/2009') AND '11/23/2009')))))

          modified on Tuesday, December 29, 2009 8:38 PM

          J Offline
          J Offline
          James Shao
          wrote on last edited by
          #4

          Can anyone please help me? I still can't figure out how to write this....

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups