Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
good morning,
i'm trying to put an if statment in the query but with select doesn't work.
Soggetti:
SQL
if prod.diapason.ansadid.ancoco = 'CE90125'
Select
prod.diapason.ocsaorh.ochclid as Cliente,
prod.diapason.ansaind.innaz as Nazione,
prod.diapason.ansadid.ancoco as ClienteStruttura,
prod.diapason.ansadid.aninco as RagioneSocialeCliente,
substring(prod.diapason.dwstrsogg.cliente_l2,9,50) as Gruppo1,
substring(prod.diapason.dwstrsogg.cliente_l3,9,50) as Gruppo2
from prod.diapason.ansadid
inner join prod.diapason.dwstrsogg
on prod.diapason.ansadid.ancoso = prod.diapason.dwstrsogg.codsoclogi
and prod.diapason.ansadid.ancoco = prod.diapason.dwstrsogg.codcliente
inner join prod.diapason.ocsaorh
on prod.diapason.ansadid.ancoco = prod.diapason.ocsaorh.ochclid
inner join prod.diapason.ansaind on prod.diapason.ansadid.ancoco = prod.diapason.ansaind.ancoco
where
prod.diapason.ansadid.ancoso = 'FIPPI';
else
Select
prod.diapason.ansadid.ancoco as Cliente,
prod.diapason.ansaind.innaz as Nazione,
prod.diapason.ansadid.ancoco as ClienteStruttura,
prod.diapason.ansadid.aninco as RagioneSocialeCliente,
substring(prod.diapason.dwstrsogg.cliente_l1,9,50) as Gruppo1,
substring(prod.diapason.dwstrsogg.cliente_l2,9,50) as Gruppo2,
prod.diapason.dwstrsogg.cliente_l3 as Gruppo3,
prod.diapason.dwstrsogg.cliente_l4 as Gruppo4
from prod.diapason.ansadid
inner join prod.diapason.dwstrsogg
on prod.diapason.ansadid.ancoso = prod.diapason.dwstrsogg.codsoclogi
and prod.diapason.ansadid.ancoco = prod.diapason.dwstrsogg.codcliente
inner join prod.diapason.ansaind on prod.diapason.ansadid.ancoco = prod.diapason.ansaind.ancoco
inner join
where
prod.diapason.ansadid.ancoso = 'FIPPI';
how could i do?
thank u
Hi maybe there is a better way but it looks like an union with an additional where condition can do the trick:
Select... [first select] where prod.diapason.ansadid.ancoso = 'FIPPI' and prod.diapason.ansadid.ancoco = 'CE90125'
Union all
Select... [secondselect] where prod.diapason.ansadid.ancoso = 'FIPPI' and prod.diapason.ansadid.ancoco <> 'CE90125'