lulazz
Posts: 29
|
| Posted: 08/02/2007, 5:15 AM |
|
Hi,
I created a report and everything is fine, now I need to add a field....
Probabily the best thing to explain what I need is showing you the SQL for the report
SELECT s_pazienti.data, pazienti.nominativo, pazienti.sesso,pazienti. telefono, pazienti.usl, pazienti.cartella, datidoc_car.valore, pazienti.reparto
FROM datidoc_car LEFT JOIN (a_pazienti INNER JOIN (pazienti INNER JOIN s_pazienti ON
pazienti.seriale = s_pazienti.codice) ON
a_pazienti.seriale = pazienti.codice) ON
datidoc_car.riferimento = pazienti.seriale
WHERE ( s_pazienti.servizio=18 )
AND ( datidoc_car.codice=23 )
AND ( pazienti.tipo in ('D','H') )
AND ( pazienti.stato='A' )
group by 8,7,5,6,4,3,2,1
order by reparto, valore DESC, s_pazienti.data
in the same query I need to retrieve datidoc_car.valore for datidoc_car.codice=8
if were writing a php program without CCS I would do 2 queries one as above (plus getting the value of pazienti.seriale) and the second one would simply be
SELECT valore from datidoc_car
WHERE datidoc_car.codice=8
AND riferimento=$seriale
and use all the fields to create a table
How can I do this with CCS?
Also since I am not proficient with SQL would it be possible to do it in a single query?
Thanks and sorry for the long post
|
 |
 |
lulazz
Posts: 29
|
| Posted: 08/02/2007, 1:39 PM |
|
I found my own solutions...
subquery
SELECT s_pazienti.data, nominativo, sesso, telefono, usl, cartella, valore, reparto, (select valore from datidoc_car
WHERE datidoc_car.codice=8 AND riferimento=pazienti.seriale) as v2
FROM datidoc_car LEFT JOIN (a_pazienti INNER JOIN (pazienti INNER JOIN s_pazienti ON
pazienti.seriale = s_pazienti.codice) ON
a_pazienti.seriale = pazienti.codice) ON
datidoc_car.riferimento = pazienti.seriale
WHERE ( s_pazienti.servizio=18 )
AND ( datidoc_car.codice =23 )
AND ( pazienti.tipo in ('D','H') )
AND ( pazienti.stato='A' )
group by reparto,7,5,6,4,3,2,1,9
order by reparto, valore DESC, s_pazienti.data
this way it works perfectly
|
 |
 |
|