I call stored procedures a lot in my BIRT reports and they've always worked quite nicely. This stored procedure, however, isn't going well. When I call the stored procedure in MySQL Workbench, I see the correct data rows returned in the results window. When I call this stored procedure in BIRT, I do not see data rows in either a table that references the data set calling the stored procedure, nor do I see any data rows in the "Preview Results" window for the data set.
(This code has been modified to keep our table names anonymous.)
DROP procedure IF EXISTS ch_dw.p_closest5rxproviders;
DELIMITER //
CREATE PROCEDURE ch_dw.p_closest5rxproviders(i_participantid INT(11))
BEGIN
/*************************************************************************************
Create Date: 21-AUG-2012
Author: Megan Ewers
Purpose: SQL to get the 5 closest providers for each rx brand dosage id in savings.
Frequency: Run as needed
Revision History: Dev Track #? -
*************************************************************************************/
DECLARE v_participantid INT(11);
SET v_participantid = i_participantid;
SELECT *
FROM (SELECT s1.rx_brand_dosage_id rx_1,
COUNT(s1.rx_brand_dosage_id) rx_count
FROM chc_etl.TABLE_S s1
JOIN chc_etl.TABLE_ST st on s1.saving_type_id = st.id
JOIN chc_etl.TABLE_SP sp on s1.id = sp.saving_id
JOIN chc_etl.TABLE_MP mp on sp.medical_provider_id = mp.id
LEFT JOIN chc_etl.TABLE_PSC psc on s1.provider_service_code_id = psc.id
LEFT JOIN chc_etl.TABLE_PG pg on s1.provider_grouping_id = pg.id
WHERE rx_brand_dosage_id IS NOT NULL
AND s1.state = 'new'
AND s1.participant_id = v_participantid
GROUP BY 1
HAVING COUNT(s1.rx_brand_dosage_id) > 5) a,
(SELECT q1.medical_provider_id,
q1.rx_brand_dosage_id,
q1.distance,
q1.address1,
q1.address2,
q1.city,
q1.state,
q1.zipcode,
IF(
@prev <> q1.rx_brand_dosage_id,
@rownum := 1,
@rownum :=
@rownum + 1) AS rank,
@prev := q1.rx_brand_dosage_id rx_3
FROM (SELECT DISTINCT s.rx_brand_dosage_id,
pa.medical_provider_id,
pa.address_type,
pa.address1,
pa.address2,
pa.city,
pa.state,
pa.zipcode,
mp.latitude,
mp.longitude,
round((((acos(sin((p.latitude*pi()/180)) *
sin((mp.latitude*pi()/180))+
cos((p.latitude*pi()/180)) *
cos((mp.latitude*pi()/180)) *
cos(((p.longitude-
mp.longitude)*pi()/180))))*180/pi())*60*1.1515)) distance
FROM chc_etl.TABLE_U u,
chc_etl.TABLE_P p,
chc_etl.TABLE_S s,
chc_etl.TABLE_ST st,
chc_etl.TABLE_SP sp,
chc_etl.TABLE_MP mp,
chc_etl.TABLE_PA pa
WHERE s.user_id = u.id
AND u.id = p.user_id
AND s.state = 'new'
AND s.id = sp.saving_id
AND s.saving_type_id = st.id
AND sp.medical_provider_id = mp.id
AND mp.id = pa.medical_provider_id
AND pa.address_type = 'Primary'
AND s.participant_id = v_participantid
ORDER BY rx_brand_dosage_id, distance asc) q1) b
WHERE a.rx_1 = b.rx_brand_dosage_id
AND b.rank <= 5
ORDER BY a.rx_1, b.rank asc
;
END //
DELIMITER ;
We even tried to "fake out" BIRT by changing this procedure to create a table called "provider_distances" to insert the rows into and then did this:
DROP procedure IF EXISTS ch_dw.p_birt_test;
DELIMITER //
CREATE PROCEDURE ch_dw.p_birt_test(i_participant INT(11))
BEGIN
DROP TABLE IF EXISTS ch_dw.provider_distances;
call p_closest5rxproviders(513624);
SELECT rx_1,
rx_count,
medical_provider_id,
rx_brand_dosage_id,
distance,
address1,
address2,
city,
state,
zipcode,
rank,
rx_3
FROM ch_dw.provider_distances;
DROP TABLE IF EXISTS ch_dw.provider_distances;
END //
DELIMITER ;
It still returned no data rows.
If we ran this: call p_closest5rxproviders(513624);
and then did this:
DROP procedure IF EXISTS ch_dw.p_birt_test;
DELIMITER //
CREATE PROCEDURE ch_dw.p_birt_test(i_participant INT(11))
BEGIN
#DROP TABLE IF EXISTS ch_dw.provider_distances;
#call p_closest5rxproviders(i_participant);
SELECT rx_1,
rx_count,
medical_provider_id,
rx_brand_dosage_id,
distance,
address1,
address2,
city,
state,
zipcode,
rank,
rx_3
FROM ch_dw.provider_distances;
DROP TABLE IF EXISTS ch_dw.provider_distances;
END //
DELIMITER ;
then we got the data to appear in BIRT. So what we determined is BIRT *really* hates something in the p_closest5rxproviders stored procedure. My gut is telling me that one of these two lines is the culprit because I've never used anything like this in the other stored procedures I've called in BIRT:
IF(
@prev <> q1.rx_brand_dosage_id,
@rownum := 1,
@rownum :=
@rownum + 1) AS rank,
@prev := q1.rx_brand_dosage_id rx_3
Ideas for how to do our little ranking magic somehow that won't tick BIRT off?