Skip to content
Advertisement

CTE function with insert statement

I have 2 queries and I need to combine them into one query with an insert statement.

This is my first query that already has an insert statement:

This is the result from first query in table REPORTDATA:

enter image description here

And this is my second query.

And this is the result from second query:

enter image description here

I want to place it into my first query but I don’t know how to combine it into one in insert statement. Can anyone solve my problems?

This is the sample to my first query: Count summary records per month with conditional SQL and this is the sample to second query: Count records per month with condition in SQL Server

Advertisement

Answer

It’s easy if you concatenate your queries as multiple CTEs, and finally JOIN them.

Like this :

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement