View Full Version : Please help for right join with more than 3 table
polachan 08-15-2008, 03:10 AM Please help to solve the following queries. It is not working please help
SELECT
roqtarget.depotcode as depotcode,
sum(roqanalysis.linetotal) as td_sales,
sum(roqanalysis.linecost) as td_cost,
td_sales-td_cost as td_profit,
td_profit/td_sales *100 as td_margin,
sum(roqtarget.saletarget) as td_depot_target,
(td_profit/td_depot_target ) *100 as td_pcnt_to_tgt,
td_depot_target - td_profit as td_required
from roqanalysis,
right join roqtarget
ON roqtarget.depotnumber = roqanalysis.depotnumber
and roqtarget.targetdate = roqanalysis.invdate
right join roqdepot
ON roqdepot.id= roqanalysis.depotnumber
where
roqtarget.depotnumber in1)
group by
roqtarget.depotcode
order by roqtarget.depotcode
MSAccessRookie 08-15-2008, 05:34 AM Please help to solve the following queries. It is not working please help
SELECT
roqtarget.depotcode as depotcode,
sum(roqanalysis.linetotal) as td_sales,
sum(roqanalysis.linecost) as td_cost,
td_sales-td_cost as td_profit,
td_profit/td_sales *100 as td_margin,
sum(roqtarget.saletarget) as td_depot_target,
(td_profit/td_depot_target ) *100 as td_pcnt_to_tgt,
td_depot_target - td_profit as td_required
from ((roqanalysis, right join roqtarget
ON ((roqtarget.depotnumber = roqanalysis.depotnumber)
and (roqtarget.targetdate = roqanalysis.invdate)))
(right join roqdepot ON roqdepot.id = roqanalysis.depotnumber))
where
roqtarget.depotnumber in (1) {Something may have been lost here}
group by roqtarget.depotcode,
td_sales-td_cost,
td_profit/td_sales *100,
(td_profit/td_depot_target ) *100,
td_depot_target - td_profit
order by roqtarget.depotcode
PURPLE denotes Selected Columns fields with GROUP attributes (Objects of the GROUP BY Statement)
GREEN denotes Selected Columns fields without GROUP attributes (Required in the GROUP BY Statement)
RED denotes modifications to the script
NOTE: As so many others have said before me, this is "Air Code", and has not been tested, although it should work.
polachan 08-15-2008, 07:54 AM Still it is not working after giving the following ways
SELECT
roqtarget.depotcode as depotcode,
sum(roqanalysis.linetotal) as td_sales,
sum(roqanalysis.linecost) as td_cost,
td_sales-td_cost as td_profit,
td_profit/td_sales *100 as td_margin,
sum(roqtarget.saletarget) as td_depot_target,
(td_profit/td_depot_target ) *100 as td_pcnt_to_tgt,
td_depot_target - td_profit as td_required
from ((roqanalysis, right join roqtarget
ON ((roqtarget.depotnumber = roqanalysis.depotnumber)
and (roqtarget.targetdate = roqanalysis.invdate)))
(right join roqdepot ON roqdepot.id = roqanalysis.depotnumber))
where
roqtarget.depotnumber in(1,2)
group by
roqtarget.depotcode
order by roqtarget.depotcode;
MSAccessRookie 08-15-2008, 08:01 AM Still it is not working after giving the following ways
SELECT
roqtarget.depotcode as depotcode,
sum(roqanalysis.linetotal) as td_sales,
sum(roqanalysis.linecost) as td_cost,
td_sales-td_cost as td_profit,
td_profit/td_sales *100 as td_margin,
sum(roqtarget.saletarget) as td_depot_target,
(td_profit/td_depot_target ) *100 as td_pcnt_to_tgt,
td_depot_target - td_profit as td_required
from ((roqanalysis, right join roqtarget
ON ((roqtarget.depotnumber = roqanalysis.depotnumber)
and (roqtarget.targetdate = roqanalysis.invdate)))
(right join roqdepot ON roqdepot.id = roqanalysis.depotnumber))
where
roqtarget.depotnumber in(1,2)
group by
roqtarget.depotcode
order by roqtarget.depotcode;
You did not say what error you are getting, but I still think that your GROUP BY statement is incomplete (refer to the lines marked in red in my previous post). Please let me know what the error messsage is.
polachan 08-15-2008, 08:07 AM Thank you for response
The error message is coming 'syntax error in Join'
Thanks
Pol
MSAccessRookie 08-15-2008, 08:15 AM I noticed two possible problems:
There is an extra comma that is not needed
The parenthesis may be in the wrong place, and also may not be needed.
Removing what is marked in red might get the code to work.
SELECT
roqtarget.depotcode as depotcode,
sum(roqanalysis.linetotal) as td_sales,
sum(roqanalysis.linecost) as td_cost,
td_sales-td_cost as td_profit,
td_profit/td_sales *100 as td_margin,
sum(roqtarget.saletarget) as td_depot_target,
(td_profit/td_depot_target ) *100 as td_pcnt_to_tgt,
td_depot_target - td_profit as td_required
from ((roqanalysis, right join roqtarget
ON ((roqtarget.depotnumber = roqanalysis.depotnumber)
and (roqtarget.targetdate = roqanalysis.invdate)))
(right join roqdepot ON roqdepot.id = roqanalysis.depotnumber))
where
roqtarget.depotnumber in(1,2)
group by
roqtarget.depotcode
order by roqtarget.depotcode;
polachan 08-18-2008, 12:16 AM I changed the sql as you said , still the problem continue, now the error becomes Join Expression is not supported in Access
With thanks
Pol
|
|