Dong Shin 04.13.2011

  • working on SQL queries to retrieve the financial data via scripting interface… This query will retrieve all financial data with calculated goals value and checks if data is less than the goals
  • SELECT p.uid as 'Project ID', p.project_number, b.uid as 'Budget Center ID', b.center_number,
    b.appropriation, a.uid, a.year, a.amount, o.uid, o.year_count, o.month_1, o.year, o.type,
    IF (o.type like '%Outlay%', (g.outlay_month_1 * a.amount / 100), (g.obligation_month_1 * a.amount) / 100) as goal_month_1,
    IF (o.month_1 < IF (o.type like '%Outlay%', (g.outlay_month_1 * a.amount / 100), (g.obligation_month_1 * a.amount) / 100), 'FLAG', 'OK') as flag_month_1,
    
    IF (o.type like '%Outlay%', (g.outlay_month_2 * a.amount / 100), (g.obligation_month_2 * a.amount) / 100) as goal_month_2,
    IF (o.month_2 < IF (o.type like '%Outlay%', (g.outlay_month_2 * a.amount / 100), (g.obligation_month_2 * a.amount) / 100), 'FLAG', 'OK') as flag_month_21,
    
    IF (o.type like '%Outlay%', (g.outlay_month_3 * a.amount / 100), (g.obligation_month_3 * a.amount) / 100) as goal_month_3,
    IF (o.month_3 < IF (o.type like '%Outlay%', (g.outlay_month_3 * a.amount / 100), (g.obligation_month_3 * a.amount) / 100), 'FLAG', 'OK') as flag_month_3,
    
    IF (o.type like '%Outlay%', (g.outlay_month_4 * a.amount / 100), (g.obligation_month_4 * a.amount) / 100) as goal_month_4,
    IF (o.month_4 < IF (o.type like '%Outlay%', (g.outlay_month_4 * a.amount / 100), (g.obligation_month_4 * a.amount) / 100), 'FLAG', 'OK') as flag_month_4,
    
    IF (o.type like '%Outlay%', (g.outlay_month_5 * a.amount / 100), (g.obligation_month_5 * a.amount) / 100) as goal_month_5,
    IF (o.month_5 < IF (o.type like '%Outlay%', (g.outlay_month_5 * a.amount / 100), (g.obligation_month_5 * a.amount) / 100), 'FLAG', 'OK') as flag_month_5,
    
    IF (o.type like '%Outlay%', (g.outlay_month_6 * a.amount / 100), (g.obligation_month_6 * a.amount) / 100) as goal_month_6,
    IF (o.month_6 < IF (o.type like '%Outlay%', (g.outlay_month_6 * a.amount / 100), (g.obligation_month_6 * a.amount) / 100), 'FLAG', 'OK') as flag_month_6,
    
    IF (o.type like '%Outlay%', (g.outlay_month_7 * a.amount / 100), (g.obligation_month_7 * a.amount) / 100) as goal_month_7,
    IF (o.month_7 < IF (o.type like '%Outlay%', (g.outlay_month_7 * a.amount / 100), (g.obligation_month_7 * a.amount) / 100), 'FLAG', 'OK') as flag_month_7,
    
    IF (o.type like '%Outlay%', (g.outlay_month_8 * a.amount / 100), (g.obligation_month_8 * a.amount) / 100) as goal_month_8,
    IF (o.month_8 < IF (o.type like '%Outlay%', (g.outlay_month_8 * a.amount / 100), (g.obligation_month_8 * a.amount) / 100), 'FLAG', 'OK') as flag_month_8,
    
    IF (o.type like '%Outlay%', (g.outlay_month_9 * a.amount / 100), (g.obligation_month_9 * a.amount) / 100) as goal_month_9,
    IF (o.month_9 < IF (o.type like '%Outlay%', (g.outlay_month_9 * a.amount / 100), (g.obligation_month_9 * a.amount) / 100), 'FLAG', 'OK') as flag_month_9,
    
    IF (o.type like '%Outlay%', (g.outlay_month_10 * a.amount / 100), (g.obligation_month_10 * a.amount) / 100) as goal_month_10,
    IF (o.month_10 < IF (o.type like '%Outlay%', (g.outlay_month_10 * a.amount / 100), (g.obligation_month_10 * a.amount) / 100), 'FLAG', 'OK') as flag_month_10,
    
    IF (o.type like '%Outlay%', (g.outlay_month_11 * a.amount / 100), (g.obligation_month_11 * a.amount) / 100) as goal_month_11,
    IF (o.month_11 < IF (o.type like '%Outlay%', (g.outlay_month_11 * a.amount / 100), (g.obligation_month_11 * a.amount) / 100), 'FLAG', 'OK') as flag_month_11,
    
    IF (o.type like '%Outlay%', (g.outlay_month_12 * a.amount / 100), (g.obligation_month_12 * a.amount) / 100) as goal_month_12,
    IF (o.month_12 < IF (o.type like '%Outlay%', (g.outlay_month_12 * a.amount / 100), (g.obligation_month_12 * a.amount) / 100), 'FLAG', 'OK') as flag_month_12
    
    FROM projects p, budget_centers b, budget_amounts a, obligations_outlays o, obligations_outlays_goals g
    WHERE p.uid = b.project_id AND b.uid = a.budget_center_id AND b.uid = o.funding_id
    AND b.appropriation = g.appropriation AND g.year = year_count AND a.year = g.year
    ORDER BY b.uid, a.year, o.year