• Append SQL (Access97 )

    Author
    Topic
    #374144

    Hi All,

    Is it possible to combine the following SQL so that SQL1 use the results of SQL2? And if so, what syntax would I use?

    ‘SQL1
    INSERT INTO Table2 (Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field)
    SELECT Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field9

    ‘SQL2
    SELECT Table1.FIELD1, Table1.FIELD2, Sum(Table1.FIELD3) AS SumOfFIELD3, Sum(Table1.FIELD4) AS SumOfFIELD4, Sum(Table1.FIELD5) AS SumOfFIELD5, Table1.FIELD6, Table1.FIELD7, Table1.FIELD8, Table1.FIELD9
    FROM Table1

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #604257

      Since I’m assuming your fields line up from SQL2 to SQL1, you cand do this:

      INSERT INTO Table2 (Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field)
      SELECT * from SQL2

      • #604272

        Thanks Mark.

        SQL2 isn’t a saved query but you reply gave me an idea.

        I replaced the SELECT statement from SQL1 with the SQL2 SELECT statement and the correct results were returned.

        INSERT INTO Table2 (Field1, Field2, Field3, Field4, Field5, Field6, Field7, Field8, Field)
        SELECT Table1.FIELD1, Table1.FIELD2, Sum(Table1.FIELD3) AS SumOfFIELD3, Sum(Table1.FIELD4) AS
        SumOfFIELD4, Sum(Table1.FIELD5) AS SumOfFIELD5, Table1.FIELD6, Table1.FIELD7, Table1.FIELD8,
        Table1.FIELD9
        FROM Table1

        Thanks again.

    Viewing 0 reply threads
    Reply To: Append SQL (Access97 )

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: