'stock_num' is not within the scope of the joined table expression??



I'm trying to perform a two-table SELECT where each table has a column
named 'stock_num'. One of the tables, however, isn't necessarily
going to have row's for a given stock_num (it might or might not). To
get around this, I do a LEFT JOIN. Or atleast I'm trying to do one.
Unfortunately, I'm getting an error that I don't understand:

Sybase: Server message: Adaptive Server cannot perform the requested
action because column 'stock_num' is not within the scope of the
joined table expression. Check your command for missing or incorrect
database objects, variable names, and/or input data. (severity 16,
procedure N/A) in %filename% on line %linenumber%

Like I said, all the tables have the 'stock_num' column. I even
reference it in my WHERE. So why is it not "within the scope of the
joined table expression" (whatever that even means)?

Here's the SQL:
SELECT s.*
FROM location_stock ls, stock s
LEFT JOIN current_quantity cq
ON cq.stock_num = ls.stock_num
AND cq.location = 'A'
WHERE ls.location = 'A'
AND s.stock_num = ls.stock_num

If I replace s.* with COUNT(1), it works. Here's something else that
works:

SELECT ls.*
FROM location_stock ls
LEFT JOIN current_quantity cq
ON cq.stock_num = ls.stock_num
AND cq.location = 'A'
WHERE ls.location = 'A'

So why doesn't the first query work?

.



Relevant Pages

  • Re: stock_num is not within the scope of the joined table expression??
    ... Sybase: Server message: Adaptive Server cannot perform the requested ... Check your command for missing or incorrect ... database objects, variable names, and/or input data. ... So why is it not "within the scope of the ...
    (comp.databases.sybase)
  • stock_num is not within the scope of the joined table expression??
    ... Sybase: Server message: Adaptive Server cannot perform the requested ... Check your command for missing or incorrect ... database objects, variable names, and/or input data. ... So why is it not "within the scope of the ...
    (comp.databases.sybase)
  • Re: stock_num is not within the scope of the joined table expression??
    ... Sybase: Server message: Adaptive Server cannot perform the requested ... database objects, variable names, and/or input data. ... So why is it not "within the scope of the ... FROM location_stock ls, stock s ...
    (comp.databases.sybase)
  • Re: Returning a CHAR[] from a function
    ... Your function is incorrect. ... which goes out of scope as soon as the function has finished. ... std::string or CString rather than returning a pointer to a buffer. ...
    (microsoft.public.vc.mfc)
  • Re: array help
    ... This guess is incorrect. ... YOU did something wrong, not Perl. ... the scope of line 24". ... Paul Lalli ...
    (perl.beginners)