We will see a very simple script where we will take advantage of the Common Table Expression and list all dates between two dates (Start and End Date).
SQL SERVER – CTE can be Updated
Today I have received a fantastic email from Matthew Spieth. SQL Server expert from Ohio. He recently had a great conversation with his colleagues in the office and wanted to make sure that everybody who reads this blog knows about this little feature which is commonly confused. Here is his…
Read MoreSQL SERVER – Does Use of CTE Change the Order of Join in Inner Join
I just had an interesting conversation the day before when I was discussing about Join Order in one of my recent presentations. The comment which triggered all the conversation was “If I want to change the order of how tables are joined in SQL Server, I prefer to use CTE…
Read MoreSQL Server – Multiple CTE in One SELECT Statement Query
I have previously written many articles on CTE. One question I get often is how to use multiple CTE in one query or multiple CTE in SELECT statement. Let us see quickly two examples for the same. I had done my best to take simplest examples in this subject. Option…
Read MoreSQL SERVER – SQL SERVER – Simple Example of Recursive CTE – Part 2 – MAXRECURSION – Prevent CTE Infinite Loop
Yesterday I wrote about SQL SERVER – SQL SERVER – Simple Example of Recursive CTE. I right away received email from regular reader John Mildred that if I can prevent infinite recursion of CTE. Sure! recursion can be limited. Use the option of MAXRECURSION. USE AdventureWorks GO WITH Emp_CTE AS…
Read MoreSQL SERVER – Simple Example of Recursive CTE
Recursive is the process in which the query executes itself. It is used to get results based on the output of base query. We can use CTE as Recursive CTE (Common Table Expression). You can read my previous articles about CTE by searching at http://search.SQLAuthority.com . Here, the result of…
Read MoreSQL SERVER – How to Retrieve TOP and BOTTOM Rows Together using T-SQL – Part 2 – CTE
Please read SQL SERVER – How to Retrieve TOP and BOTTOM Rows Together using T-SQL before continuing this article. I had asked users to come up with an alternate solution of the same problem. In this blog post we will see solution with the help of CTE.Â