0

YQL Statement Problem

Hi,

I've been going bonkers trying to figure out what's wrong with my statement:

select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')

Syntax error(s) [line 1:165 mismatched input 'like' expecting ISNOTNULL]
select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')

I don't see why I need this ISNOTNULL.

Any suggestions?

Thanks!

by
  • A.
  • Jan 10, 2010
7 Replies
  • QUOTE (anonymousities @ Jan 10 2010, 10:16 PM) <{POST_SNAPBACK}>
    Hi,

    I've got a problem with my statement:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')

    Syntax error(s) [line 1:165 mismatched input 'like' expecting ISNOTNULL]
    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')

    I want to, if the Symbol look up fails, use the query in a wildcard Name search. I guess this means I need two separate SQL statements for the two situations, right?

    Thanks!
    0
  • Crud, sorry about that. I don't see how to edit posts, and then I accidentally put my edit in quotes. :P
    0
  • QUOTE (anonymousities @ Jan 10 2010, 10:16 PM) <{POST_SNAPBACK}>
    I've been going bonkers trying to figure out what's wrong with my statement:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')

    Syntax error(s) [line 1:165 mismatched input 'like' expecting ISNOTNULL]
    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Symbol in ('YHOO') OR Name like ('YHOO%')


    Hi,

    first of all, you should say "name like 'YHOO%'", without the brackets.

    Stripping down your query, this is a statement that's working:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where symbol in ("YHOO")


    Now if you replace the where-clause by the second part of your where-clause, you get this:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Name like "YHOO%"


    This query gives an error, because it lacks the required key 'symbol'. Now you can see it's quite obvious that if you combine clauses with 'OR', all of them should have the mandatory keys, because each member of the 'OR' is in fact a separate query.

    Notice that following query does work, because now the clauses are combined with 'AND', and the 'name'-condition is applied as a local filter to the data that is retrieved by using the 'symbol'-condition as a remote filter:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where symbol in ("YHOO") and Name like "Yahoo%"


    Also, there's a lot of case-sensitivity issues going on in this table definition...

    Regards,
    Vic
    0
  • Thanks for your help, Vic. However, my problem is not solved.

    In my application, I want my users to look up stocks by (a) symbol or (B) name. The inputs are received in the same box, so I was hoping that the OR statement would let users do either. Any advice on how I can implement this? I suppose I need to go outside my YQL statement, then?
    0
  • QUOTE (anonymousities @ Jan 12 2010, 11:49 AM) <{POST_SNAPBACK}>
    Thanks for your help, Vic. However, my problem is not solved.

    In my application, I want my users to look up stocks by (a) symbol or (B)Vic
    0
  • QUOTE (vic m @ Jan 12 2010, 01:35 PM) <{POST_SNAPBACK}>
    The table you're using relies on the 'symbol' to be queried, because basically what happens is that this webservice is called:

    http://download.finance.yahoo.com/d/quotes...tjoin|,|symbol}

    If you dig into the yahoo finance webservice API, you may find a way to retrieve similar data based on stock names and you could create your own open table for processing that data....

    I don't know anything about these webservices, so can't help any further.

    Groeten,
    Vic


    Vic, thanks for your help. Somehow, my query keeps returning NULL.

    {
    CODEBOX
    function yqlGetAll($stockSymbol)	{
    require("yahooSDK/Yahoo.inc");
    define("API_KEY"<omitted>);
    define("SHARED_SECRET",<omitted>);

    $two_legged_app = new YahooApplication(API_KEY,SHARED_SECRET);
    if ($two_legged_app == NULL) {
    return false;
    }

    $symbolQuery = "select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where symbol in ('$stockSymbol')";
    $symbolResponse = $two_legged_app->query($symbolQuery);

    var_dump($symbolResponse);
    }


    Any suggestions? I followed the code examples (http://developer.yahoo.com/yql/guide/yql-code-examples.html#sdk_yql) pretty closely.
    0
  • I updated my YQL statement. I fixed a concatenation problem and added USE, AS statements.

    CODEBOX
    $symbolQuery = "USE 'http://test.atlambert.com/stuff/yahoo.finance.quotes.xml' AS yahoo.finance.quotes; SELECT Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime FROM yahoo.finance.quotes WHERE Symbol IN ('" . $stockSymbol . "')";


    However, I'm getting that goofy key problem I had earlier:

    QUOTE (vic m @ Jan 12 2010, 01:21 AM) <{POST_SNAPBACK}>
    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where Name like "YHOO%"


    This query gives an error, because it lacks the required key 'symbol'. Now you can see it's quite obvious that if you combine clauses with 'OR', all of them should have the mandatory keys, because each member of the 'OR' is in fact a separate query.

    Notice that following query does work, because now the clauses are combined with 'AND', and the 'name'-condition is applied as a local filter to the data that is retrieved by using the 'symbol'-condition as a remote filter:

    select Name,Symbol,LastTradePriceOnly,Open,DaysHigh,DaysLow,Volume,PercentChange,AfterH
    oursChangeRealtime from yahoo.finance.quotes where symbol in ("YHOO") and Name like "Yahoo%"


    I don't understand why I need to add an "AND" or "OR" to this. Why can't I just look up all the fields for the given stock symbol?

    My goal is to scrape the info for the given stock symbol. Let me know if you have ideas. Thanks!!
    0

Recent Posts

in YQL