Friday, February 5, 2016

Outer Apply in SQL Server

In one of our previous discussion, we discussed about the concept of Cross apply in sql. In this article we will discuss about the Outer apply. If you have not read that then I would suggest you to go through it here first, as we will use the same data & tables. So let's start with it.

So now we will add another category Category 3, in the Category table. But this will have no Product associated with it. So we will first use the Left Join and see the results we get.

Now on order to use the Outer apply, our query will remain the same as it was in previous article except the Cross keyword will be replaced with the Outer keyword. Let's change it and see the results.

Now, as we discussed earlier that Apply can be used with the Table Valued functions also, we will use the same function which we created earlier and simply call that function using the Outer apply So let's change the call to use Outer apply.

Easy to learn. Happy Querying...!!!