Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

The following does not work as expected. I get Incorrect syntax near ','. (See code)
SELECT Time_class, Time_instance, Geo_class, Aggregated_area, Super_cl +assed_disease_cat, Cause, Constraint_ref, Sex, Sex_code, Age_start, A +ge_end, Age_range, Sum_count = SUM(G.Converted_person_count) INTO #tmp_G_P_M_CC_S_S FROM Geo_postaggregated_mortality_count_with_cause_catagor +y_SPLIT_SMR G GROUP BY G.Time_class, G.Time_instance, G.Geo_class, G.Agg +regated_area, G.Super_classed_disease_cat, G.Cause, G.Constraint_ref, + G.Sex, G.Sex_code, G.Age_start, G.Age_end, G.Age_range DECLARE @Key AS INT SET @Key = 1 while @Key <= (SELECT MAX(Key_m) FROM Geo_postaggregated_morta +lity_count_with_cause_catagory_SPLIT_SMR) begin UPDATE Geo_postaggregated_pop_count_SPLIT SET Total_person_count = t.Sum_count FROM Geo_postaggregated_mortality_count_with_cause_cata +gory_SPLIT_SMR G, #tmp_G_P_M_CC_S_S t WHERE G.Key_m = @Key, --- Problem is here G.Time_instance = t.Time_instance, G.Geo_class = t.Geo_class, G.Aggregated_area = t.Aggregated_area, G.Super_classed_disease_cat = t.Super_classed_disease_cat, G.Cause = t.Cause, G.Constraint_ref = t.Constraint_ref, G.Sex = t.Sex, G.Sex_code = t.Sex_code, G.Age_start = t.Age_start, G.Age_end = t.Age_end, G.Age_range = t.Age_range SET @Key = @Key +1 end
Please help if you can. Perl/sql or Perl or SQL.

Replies are listed 'Best First'.
Re: SQL Problem. Perl solution?
by Util (Priest) on Sep 23, 2005 at 18:36 UTC

    In SQL, the WHERE clause does not take a list; it takes an expression. So replace the commas with 'AND's.

    UPDATE Geo_postaggregated_pop_count_SPLIT SET Total_person_count = t.Sum_count FROM Geo_postaggregated_mortality_count_with_cause_catagory_SPLIT_ +SMR G, #tmp_G_P_M_CC_S_S t WHERE G.Key_m = @Key AND G.Time_instance = t.Time_instance AND G.Geo_class = t.Geo_class AND G.Aggregated_area = t.Aggregated_area AND G.Super_classed_disease_cat = t.Super_classed_disease_cat AND G.Cause = t.Cause AND G.Constraint_ref = t.Constraint_ref AND G.Sex = t.Sex AND G.Sex_code = t.Sex_code AND G.Age_start = t.Age_start AND G.Age_end = t.Age_end AND G.Age_range = t.Age_range
    But whether or not this works, please take Mutant's advice.

Re: SQL Problem. Perl solution?
by Mutant (Priest) on Sep 23, 2005 at 15:49 UTC
    Please read How do I post a question effectively?

    It's extremely difficult to help you without some more information on what you're trying to achieve, a bit more background, some examples of what you've tried, etc.
Re: SQL Problem. Perl solution?
by davidrw (Prior) on Sep 23, 2005 at 15:55 UTC
    What database is this? Why does the solution need to moved from sql to (perl) code?

    The table name of #tmp_G_P_M_CC_S_S immediately jumps out at me -- that should probably be quoted as "#tmp_G_P_M_CC_S_S" and could quite possibly be the problem...