Home Forums Programming General call for SQL statements sepcialists! :-) RE: call for SQL statements sepcialists! :-)

  • Hi visbek !

    It took me some time to get the picture 🙂 but after that it was obvious. I think the problem is in the way the type info view is JOINDed to other two views. The right approach would be to make separate summaries from qryPublicate and qryInfoAanVraag and JOIN them to qryInfoType to get the description. I will only scratch the SQL:

    SELECT TOP 100 PERCENT

      <columns from qryTypeInfo>, <columns from Tmp_Publicate>, <columns from Tmp_InfoAanVraag>

    FROM qryTypeInfo

      LEFT OUTER JOIN (SELECT type_info_id, SUM(aantal) AS Publicate_aantal, SUM(kostprijs) AS Publicate_kostprijs

                               FROM qryPublicate GROUP BY type_info_id) AS Tmp_Publicate

                               ON (Tmp_Publicate.type_info_id = qryTypeInfo.id)

      LEFT OUTER JOIN (SELECT type_info_id, SUM(aantal) AS InfoAanVraag_aantal

                                FROM qryInfoAanVraag GROUP BY type_info_id) AS Tmp_InfoAanVraag

                                ON (Tmp_InfoAanVraag.type_info_id = qryTypeInfo.id)

     

    Additional columns for COUNT and the difference should be added, too.

    I hope this will help,

     

    Regards,

    Goce Smilevski.