background preloader

Database

Facebook Twitter

Source

Microsoft SQL Server - Using CROSS APPLY in SQL Server 2005 - SQ. By Bill Graziano on 4 May 2005 | 18 Comments | Tags: Queries, User Defined Functions My interest in writing this article was started by an MSDN article titled SQL Server 2005: The CLR Enters the Relational Stage. The article shows how to write a function that returns the top three countries per category. That's always been something that was difficult to do in SQL so I was curious about the approach. The article started out well but I was very unhappy by the end.

It's just soooo much easier to do this in SQL Server 2005 using the new CROSS APPLY clause in Transact-SQL. So I'm going to write a query to return the top 3 orders for each customer and I'm going to do it in about 10 lines of SQL. First please take a second to read the MSDN article. Note: I also want to mention here that I started out trying to replicate their solution. Let's start at the TOP Along the way to making this solution work we'll discuss a few new features of SQL Server 2005. My Function Apply the APPLY Clause. Library of Free Data Models. Pro: The leading O/R mapper - generator. Books Online. Welcome to Microsoft® Books Online for Microsoft SQL Server 2012®. Books Online contains the task descriptions and reference documentation that describes how to perform data management and business intelligence work by using SQL Server.

SQL Server 2012 introduces two significant documentation changes; a new help viewer that changes the way that you install and view the documentation, and the documentation has been restructured to address issues with previous versions of Books Online. SQL Server 2012 Books Online contains a smaller set of foundation content optimized for users who are searching for information about how to complete a task. For more information, see SQL Server Documentation Restructure. SQL Server 2012 Books Online uses the help viewer released with Microsoft® Visual Studio 2010 Service Pack 1 (SP1). Also, the SQL Server documentation is no longer included in the installation media, but must be either viewed online, or downloaded as a local help collection.

Peter's Gekko : Visual Studio 2005 and Firebird.