Monday, March 12, 2012

Help with Query

Is it possible to do this all in one stored procedure?
I have 3 separate queries which returns all the correct records with
Stockcode being the field to join
Q1 is my main query from which I want to return all the records.
Q2 and Q3 return records but not every record in Query1 will have record in
Q2 and Q3.
i.e. SELECT Q1.*, Q2.Sales, Q3.Receipts
FROM Q1 LEFT JOIN Q2 ON Q1.StockCode = Q2.StockCode LEFT JOIN Q3 ON
Q1.StockCode = Q3.StockCode
WHERE Q1.Qty > 0 AND Q2.Sales <= (Q1.Qty * 0.3)
In subqueries I know you can use a subquery in the FROM clause is it
possible to have a subquery as part of the JOIN syntax?
Worked it out I think
"Newbie" <nospam@.noidea.com> wrote in message
news:uBoxXq7KFHA.1916@.TK2MSFTNGP12.phx.gbl...
> Is it possible to do this all in one stored procedure?
> I have 3 separate queries which returns all the correct records with
> Stockcode being the field to join
> Q1 is my main query from which I want to return all the records.
> Q2 and Q3 return records but not every record in Query1 will have record
> in Q2 and Q3.
> i.e. SELECT Q1.*, Q2.Sales, Q3.Receipts
> FROM Q1 LEFT JOIN Q2 ON Q1.StockCode = Q2.StockCode LEFT JOIN Q3 ON
> Q1.StockCode = Q3.StockCode
> WHERE Q1.Qty > 0 AND Q2.Sales <= (Q1.Qty * 0.3)
> In subqueries I know you can use a subquery in the FROM clause is it
> possible to have a subquery as part of the JOIN syntax?
>

No comments:

Post a Comment