My basic issue is that I have a procedure that has 10 steps, 9 of which are other stored procedures. When I call the main procedure manually (via MS SQL Management Studio) it works correctly. When I issue the same EXEC command and parameter from a PHP script via PDO. it runs the procedure, but only the first 9 steps execute. No errors are reported back to PDO, and there's no errors when running manually. Any thoughts? In case I'm doing something wacky in my SQL causing this, below are the procedures I'm running:CREATE PROCEDURE main_procedure (@uid int)AS BEGIN DECLARE @NOW DATETIME SET @NOW = getDate() DELETE FROM metrics WHERE uid = @uid AND timestamp < @NOW EXEC update_metric_a @uid, @NOW EXEC update_metric_b @uid, @NOW EXEC update_metric_c @uid, @NOW EXEC update_metric_d @uid, @NOW EXEC update_metric_e @uid, @NOW EXEC update_metric_f @uid, @NOW EXEC update_metric_g @uid, @NOW EXEC update_metric_h @uid, @NOW EXEC update_metric_i @uid, @NOWEND
This is the template used for each metric. It creates a row in the database and populates each column with averages for that individual for a given month. The other 8 are similar.CREATE PROCEDURE update_metric_a (@uid int, @NOW datetime)AS DECLARE @date datetime DECLARE @metric NUMERIC(15,4) DECLARE @metric_name VARCHAR(50) DECLARE @year_to_date_value NUMERIC(15,4) SET @metric_name = 'Metric A' INSERT INTO metric (metric_name, timestamp, uid) VALUES (@metric_name, @NOW, @uid) DECLARE monthly_metric CURSOR FOR SELECT DATEADD(month, DATEDIFF(month, 0, [date]), 0) [Date], CASE WHEN COUNT(id) > 0 THEN 1.00 * SUM(score) / COUNT(id) ELSE null END AS [average] FROM metric_outages WHERE uid = @uid AND [date] >= DATEADD(month,-12,DATEADD(month, DATEDIFF(month, 0, getdate()), 0) ) GROUP BY DATEADD(month, DATEDIFF(month, 0, [date]), 0) ORDER BY DATEADD(month, DATEDIFF(month, 0, [date]), OPEN monthly_metric FETCH NEXT FROM monthly_metric INTO @date, @metric WHILE @@FETCH_STATUS = 0 BEGIN IF @date = DATEADD(month,0, DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) UPDATE metric SET month_cur = CAST(@metric AS Varchar(20)) WHERE uid = @uid AND timestamp = @NOW AND metric = @metric_name ELSE IF @date = DATEADD(month,-1,DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) UPDATE metric SET month_1 = CAST(@metric AS Varchar(20)) WHERE uid = @uid AND timestamp = @NOW AND metric = @metric_name ... and so on ... ELSE IF @date = DATEADD(month,-12,DATEADD(month, DATEDIFF(month, 0, getdate()), 0)) UPDATE metric SET month_12 = CAST(@metric AS Varchar(20)) WHERE uid = @uid AND timestamp = @NOW AND metric = @metric_name FETCH NEXT FROM monthly_metric INTO @date, @metric END CLOSE monthly_metric DEALLOCATE monthly_metric