Skip to content
Advertisement

Can I use a CTE to make these two tables become one?

Is there any way I can make these two queries become one query? I need all of this to be in one table. Currently I’m not using any common table expression and I believe if I use them I can make these two codes into one single table.

I would also like a column called ‘G’ which is a sum of ‘E’ and ‘F’

Is there any way I can combine these two queries into one?

This is my code for two seperate queries:

Advertisement

Answer

You don’t need a CTE; just insert both sets of data into your table variable.

Also, you should avoid converting a datetime value to a string just to remove the time portion; just cast it to date.

And if you’re testing for records where the PercentageRate is greater than 0.1, you don’t also need to test whether PercentageRate is NOT NULL; a NULL value will not pass the greater-than test.

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