Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

CTE VS PIVOT

$
0
0

I have two tsql command that gives me the same result. 

I want to know which one is better and I looked at the execution place.

1st query : I used two CTE to pull the data from same table and joined at the end.

In the execution plan main table was hit 4 times with the cost 11 % each time.

2nd query : I pull the data from main table and then pivoted it.

In the execution plan main table was hit twice with the cost of 23 % each time and in sorting it took 30 %. 

WHICH QUERY SHOULD BE USED AND IS IT OKAY TO HIT THE MAIN TABLE MANY TIMES THAN NEEDED?

 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>