Skip to Content
0
Jul 22, 2009 at 10:14 AM

Select case with query

27 Views

Hello experts.

i'm in sales offer > table OQUT.

It is possible to have a FMS that select a query depending the OQUT.cardcode??

E.G.

if cardcode is A then run query A

else cardcode is B then run query B

i try this query :

SELECT CASE  $[OQUT.cardcode]
when '+MASTERFD'  Then

select a.itemcode, a.price, c.itmsgrpnam
from
	itm1 a
	inner join oitm b on a.itemcode = b.itemcode
	inner join oitb c on b.itmsgrpcod = c.itmsgrpcod
where
a.pricelist = (select listnum from ocrd where cardcode = $[OQUT.CardCode]) and
c.itmsgrpnam = $[OQUT.U_JDT_OFF_MER] and
(a.price <> 0 and a.price is not null)
for browse

else

select a.itemcode, c.itemname, a.price, a.fromdate, a.todate, d.itmsgrpnam, a.linenum
from spp1 a inner join
	(select cardcode, itemcode, max(todate) as ultimo from spp1 group by cardcode, itemcode) b
	on a.cardcode = b.cardcode and a.itemcode = b.itemcode and a.todate = b.ultimo
inner join oitm c on a.itemcode = c.itemcode
inner join oitb d on c.itmsgrpcod = d.itmsgrpcod
where a.cardcode = $[$4.0]

end

Than's in advence...

And sorry for my english....