10 Developer Features Introduced in SQL Server 2008

10
10 developer features introduced in SQL server 2008. Feature -1 Change's in the DATE and TIME DataTypes In SQL Server 2005, there were DATETIME or SMALLDATETIME data types to store datetime values but there was no specific datatype to store date or time value only. In addition, search functionality doesn't work on DATETIME or SMALLDATETIME fields if you only specify a data value in the where clause. For example the following SQL query will not work in SQL server 2005 as you have only specified the date value in the where clause. SELECT * FROM tblMyDate Where [MyDateTime] = '2010-12-11' To make it work you need to specify both date and time component in the where clause. SELECT * FROM tblMyDate Where [MyDateTime] = '2010-12-11 11:00 PM' Related Articles  SQL Server Management Features vs Oracle Database Management Features  Top 10 Features of SQL 2008 R2 With introduction of DATE datatype the above problem is resolved in SQL Server 2008. See the following example. DECLARE @mydate as DATE SET @ mydate = getdate() PRINT @dt The output from the above SQL query is the present date only (2010-12-11), no time component is added with the output. TIME datatype is also introduced in SQL server 2008. See the following query using TIME datatype. DECLARE @mytime as TIME SET @mytime = getdate () PRINT @mytime The output of the above SQL script is a time only value. The range for the TIME datatype is 00:00:00.0000000 through 23:59:59.9999999. SQL server 2008 also introduced a new datatype called DATETIME2. In this datatype, you will have an option to specify the number of fractions (minimum 0 and maximum 7). the following example shows how to use DATETIME2 datatype. DECLARE @mydate7 DATETIME2 (7) SET @mydate7 = Getdate() PRINT @mydate7 The result of above script is 2010-12-11 22:11:19.7030000. The new DATETIMEOFFSET datatype, which indicates what time zone that date and time belong to was also introduced in SQL Server 2008. This datatype will be required when you are keeping the date time value of different countries with different time zones in SQL Server. The following example shows the usage of the DATETIMEOFFSET datatype.

Transcript of 10 Developer Features Introduced in SQL Server 2008

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 1/10

10 developer features introduced in SQL server 2008.

Feature -1 Change's in the DATE and TIME DataTypes

In SQL Server 2005, there were DATETIME or SMALLDATETIME data types to store datetime valuesbut there was no specific datatype to store date or time value only. In addition, search functionality

doesn't work on DATETIME or SMALLDATETIME fields if you only specify a data value in the whereclause. For example the following SQL query will not work in SQL server 2005 as you have onlyspecified the date value in the where clause.

SELECT * FROM tblMyDate Where [MyDateTime] = '2010-12-11'

To make it work you need to specify both date and time component in the where clause.

SELECT * FROM tblMyDate Where [MyDateTime] = '2010-12-11 11:00 PM'

Related Articles

  SQL Server Management Features vs Oracle Database Management Features 

  Top 10 Features of SQL 2008 R2 

With introduction of DATE datatype the above problem is resolved in SQL Server 2008. See thefollowing example.

DECLARE @mydate as DATESET @ mydate = getdate()PRINT @dt

The output from the above SQL query is the present date only (2010-12-11), no time component isadded with the output.

TIME datatype is also introduced in SQL server 2008. See the following query using TIME datatype.

DECLARE @mytime as TIMESET @mytime = getdate ()PRINT @mytime

The output of the above SQL script is a time only value. The range for the TIME datatype is00:00:00.0000000 through 23:59:59.9999999.

SQL server 2008 also introduced a new datatype called DATETIME2. In this datatype, you will have anoption to specify the number of fractions (minimum 0 and maximum 7). the following example showshow to use DATETIME2 datatype.

DECLARE @mydate7 DATETIME2 (7)SET @mydate7 = Getdate()PRINT @mydate7

The result of above script is 2010-12-11 22:11:19.7030000.

The new DATETIMEOFFSET datatype, which indicates what time zone that date and time belong towas also introduced in SQL Server 2008. This datatype will be required when you are keeping the datetime value of different countries with different time zones in SQL Server. The following example showsthe usage of the DATETIMEOFFSET datatype.

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 2/10

DECLARE @mydatetime DATETIMEOFFSET(0)DECLARE @mydatetime1 DATETIMEOFFSET(0)SET @ mydatetime = '2010-12-11 21:53:56 +5:00'SET @ mydatetime1 = '2010-12-11 21:53:56 +10:00'SELECT DATEDIFF(hh,@mydatetime1,@mydatetime)

Feature -2 New Date and Time functions

In SQL Server 2005 and SQL Server 2000 there are few functions to retrieve the current date andtime. Adding to that In SQL Server 2008, five new functions were introduced: SYSDATETIME,SYSDATETIMEOFFSET, SYSUTCDATETIME SWITCHOFFSET and TODATETIMEOFFSET. TheSYSDATETIME function returns the present system timestamp without the time zone, with an accuracyof 10 milliseconds. The SYSDATETIMEOFFSET function works like SYSDATETIME but the onlydifference is it includes the time zone.

SYSUTCDATETIME returns the Universal Coordinated Time that is known as Greenwich Mean Timewithin an accuracy of 10 milliseconds.

Select SYSUTCDATETIME () will show output '2010-12-11 21:53:05.7131792'

SWITCHOFFSET returns a datetimeoffset value that is changed from the stored time zone offset to aspecified new time zone offset. See the following examples.

SELECT SYSDATETIMEOFFSET() GetCurrentOffSet;SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '-04:00') 'GetCurrentOffSet-4';SELECT SWITCHOFFSET(SYSDATETIMEOFFSET (), '+00:00') 'GetCurrentOffSet+0';

Feature -3 Sparse columns

Sparse column, which optimizes storage for null values, is introduced in SQL Server 2008. When a

column value contains a substantial number of null values, defining the column as sparse saves asignificant amount of disk space. In fact, null value in a sparse column doesn't take any space.

If you decide to implement a sparse column, it must be nullable and cannot be configured with theROWGUIDCOL or IDENTITY properties, cannot include a default and cannot be bound to a rule. Inaddition, you cannot define a column as sparse if it is configured with certain datatypes, such as TEXT,IMAGE, or TIMESTAMP. T following SQL script shows how to create a table with sparse column.

Create table mysparsedtable(column1 int primary key,column2 int sparse,column3 int sparse,

column4 xml column_set for all_sparse_columns)

Feature -4 Large UDTs in SQL server 2008 (ADO.NET)

User defined types (UDT's) were first introduced with SQL server 2005 but were restricted to a

maximum size of 8 kilobytes. In SQL Server 2008, this restriction has been removed. Using CommonLanguage Runtime (CLR), now SQL Server 2008 supports binary data that's up to 2GB in size. Thefollowing C# code snipped shows how to retrieve large UDT data from a SQL server 2008 database.

SqlConnection myconnection = new SqlConnection(myconnectionString, mycommandString); //myconnectionString and

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 3/10

 // mycommandString must be declaredmyconnection.Open();SqlCommand mycommand = new SqlCommand(mycommandString);SqlDataReader myreader = mycommand.ExecuteReader();while (myreader.Read()){

int id = myreader.GetInt32(0);

LargeUDT myudt = (LargeUDT)myreader[1];Console.WriteLine("ID={0} LargeUDT={1}", id, myudt);

}myreader.closeO

Feature -5 Passing tables to functions or procedures using new Table-Value parameters

SQL Server 2008 introduces a new feature to pass a table datatype into stored procedures andfunctions. The table parameter feature greatly helps to reduce the development time becausedevelopers no longer need to worry about constructing and parsing long XML data. Using this feature,you can also allow the client-side developers (using .NET code) to pass data tables from client-sidecode to the database. The following example shows how to use Table-Value parameter in storedprocedures.

In the first step, I have created a Student table using following script.

GOCREATE TABLE [dbo].[TblStudent](

[StudentID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,[StudentName] [varchar](30) NOT NULL,[RollNo] [int] NOT NULL,[Class] [varchar](10) NOT NULL

)GO

Next, I have created table datatype for Student table.

GOCREATE TYPE TblStudentTableType AS TABLE

([StudentName] [varchar](30) NOT NULL,[RollNo] [int] NOT NULL,[Class] [varchar](10) NOT NULL

)GO

Then I have created a stored procedure with table datatype as an input parameter and to insert datain Student table.

GOCREATE PROCEDURE sp_InsertStudent(@TableVariable TblStudentTableType READONLY

)ASBEGIN

INSERT INTO [TblStudent](

[StudentName] , [RollNo] , [Class]

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 4/10

)SELECT

StudentName , RollNo , Class FROM @TableVariable WHERE StudentName = 'Tapas Pal'ENDGO

In the last step, I have entered one sample student record in the table variable and executed thestored procedure to enter a sample record in the TblStudent table.

DECLARE @DataTable AS TblStudentTableTypeINSERT INTO @DataTable(StudentName , RollNo , Class)VALUES ('Tapas Pal','1', 'Xii')EXECUTE sp_InsertStudent@TableVariable = @DataTable

Feature -6 New MERGE command for INSERT, UPDATE and DELETE operations

SQL server 2008 provides the MERGE command that is an efficient way to perform multiple DML (DataManipulation Language) operations at the same time. In SQL server 2000 and 2005, we had to writeseparate SQL statements for INSERT, UPDATE, or DELETE data based on certain conditions, but in

SQL server 2008, using the MERGE statement we can include the logic of similar data modifications inone statement based on where condition match and mismatch. In the following example, I havecreated two tables (TblStudent and TblStudentMarks) and inserted sample data to show how MERGEcommand works.

GOCREATE TABLE [dbo].[TblStudent](

[StudentID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,[StudentName] [varchar](30) NOT NULL,[RollNo] [int] NOT NULL,[Class] [varchar](10) NOT NULL

)

GOCREATE TABLE TblStudentMarks(StudentID INTEGER REFERENCES TblStudent,StudentMarks INTEGER)GOINSERT INTO TblStudent VALUES('Tapas', '1', 'Xii')INSERT INTO TblStudent VALUES('Vinod', '2', 'Xiv')INSERT INTO TblStudent VALUES('Tamal', '3', 'Xii')INSERT INTO TblStudent VALUES('Tapan', '4', 'Xiii')INSERT INTO TblStudent VALUES('Debabrata', '5', 'Xv')INSERT INTO TblStudentMarks VALUES(1,230)INSERT INTO TblStudentMarks VALUES(2,280)

INSERT INTO TblStudentMarks VALUES(3,270)INSERT INTO TblStudentMarks VALUES(4,290)INSERT INTO TblStudentMarks VALUES(5,240)

Now to perform the following operations, I have written a single SQL statement.

1. Delete Record with student name 'Tapas'

2. Update Marks and Set to 260 if Marks is <= 230

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 5/10

3. Insert a record in TblStudentMarks table if the record doesn't exist

MERGE TblStudentMarks AS stmUSING (SELECT StudentID,StudentName FROM TblStudent) AS sdON stm.StudentID = sd.StudentIDWHEN MATCHED AND sd.StudentName = 'Tapas' THEN DELETEWHEN MATCHED AND stm.StudentMarks <= 230 THEN UPDATE SET stm.StudentMarks = 260

WHEN NOT MATCHED THENINSERT(StudentID,StudentMarks)VALUES(sd.StudentID,25);GO

Feature -7 New HierarchyID datatype

SQL server 2008 provides new HierarchyID data type that allows database developers to constructrelationships among data elements (columns) within a table. HierarchyID data type has a set of methods that provide tree like functionality. These methods are GetAncestor, GetDescendant,GetLevel, GetRoot, IsDescendant, Parse, Read, Reparent, ToString, Write etc. The following exampleshows how to create a HIERARCHYID column in a table.

CREATE TABLE dbo.ProductCategory(ProductSubCategoryID IDENTITY(1,1) NOT NULL ,ProductCategoryID NOT NULL,lvl AS hid.GetLevel() PERSISTED,ProductSubCatName VARCHAR(25) NOT NULL,ProductSubCatDesc VARCHAR(250)NOT NULL

)CREATE UNIQUE CLUSTERED INDEX idx_first ON dbo.Employees( ProductSubCategoryID);CREATE UNIQUE INDEX idx_second ON dbo.Employees(lvl, ProductCategoryID);

Feature -8 Spatial datatypes

Spatial is the new data type introduced in SQL server 2008 that is used to represent the physicallocation and shape of any geometric object. Using spatial data types you can represent countries,roads etc. Spatial data type in SQL server 2008 is implemented as .NET Common Language Runtime(CLR) data type. There are two types of spatial data type's available, geometry and geography datatype. Let me show you example of a geometric object.

DECLARE @point geometry;SET @point = geometry::STGeomFromText ('POINT (4 9)', 0);SELECT @point.STX; -- Will show output 4SELECT @point.STY; -- Will show output 5

You can use methods STLength, STStartPoint, STEndPoint, STPointN, STNumPoints, STIsSimple,STIsClosed and STIsRing with geometric objects.

Feature -9 Manage your files and documents efficiently by implanting FILESTREAM datatype

SQL server 2000 and 2005 do not provide much for storing videos, graphic files, word documents,excel spreadsheets and other unstructured data. In SQL Server 2005 you can store unstructured datain VARBINARY (MAX) columns but the maximum limit is 2 GB. To resolve the unstructured files storingissue, SQL Server 2008 has introduced the FILESTREAM storage option. The FILESTREAM storage isimplemented in SQL Server 2008 by storing VARBINARY (MAX) binary large objects (BLOBs) outsidethe database and in the NTFS file system. Before implementing FILESTREAM storage, you need toperform following steps.

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 6/10

1. Enable your SQL Server database instance to use FILESTREAM (enable it using thesp_filestream_configure stored procedure. sp_filestream_configure @enable_level = 3)

2. Enable your SQL Server database to use FILESTREAM

3. Create "VARBINARY (MAX) FILESTREAM" datatype column in your database

Feature -10 Faster queries and reporting with grouping sets

SQL Server 2008 implements grouping set, an extension to the GROUP BY clause that helpsdevelopers to define multiple groups in the same query. Grouping sets help dynamic analysis of aggregates and make querying/reporting easier and faster. The following is an example of groupingset.

SELECT StudentName, RollNo, Class , SectionFROM dbo.tbl_StudentGROUP BY GROUPING SETS ((Class), (Section))ORDER BY StudentName

Conclusion

The above-mentioned are the 10 most significant and beneficial features provided by SQL server 2008for developers. I hope this article will help a lot to database developers want to learn SQL server2008.

Top 10 list for Microsoft's latest version of SQL Server 2005 new features.

1. TRY/CATCH Error Control

Without doubt this is the most beneficial new feature of SQL 2005. It introduces soft error control intoT-SQL, the same kind available in standard programming languages. Well, a simplified version, but itdoes the job miraculously. Prior to SQL 2005 if a script encountered an error, that was the end. An

application can deal with it, by catching the error, but an SQL agent job written in T-SQL cannot.Typical example: you are moving million rows from a staging table to final destination. The stagingtable date is in varchar format, the destination column is datetime format. The conversion fails on “2006 janu 44”. Which is row 804249. But you only know that after ½ hour of intense research. SQL

2000 T-SQL gives no indication where it fails. It just bombs. It may have taken 10 minutes to reachthe point of failure; it may take another 10 minutes to roll back the 804248 good insert transactions;at the end you ended up with nothing. In SQL 2005 T-SQL, instead of bombing, control is passed tothe CATCH routine that for example can log the erroneous data, and upon finishing with it, the controlflow is returned to a designated T-SQL statement. If this processing is in a loop, the loop wouldcontinue. Here is an example. If you change 1/0 to 1/1, it will not go to the CATCH processing; the"try" succeeds.

PRINT 'Start of processing'BEGIN TRY

-- Generate a divide-by-zero error.SELECT Infinity = 1/0;PRINT 'No error'END TRYBEGIN CATCHSELECTERROR_NUMBER() AS ErrorNumber,

ERROR_SEVERITY() AS ErrorSeverity,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage;

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 7/10

PRINT 'Error occured'END CATCH;PRINT 'Processing continues'GO 

In SQL 2000 and prior T-SQL, the divide by zero would terminate all processing, open transactionswould be rolled back, and no opportunity would be given to recover from the error and continueprocessing. The error is raised though which can be processed by an application.

With TRY/CATCH, errors can be taken care of on the server side without involving the clientside at all. That is a huge productivity gain; also it leads to a more reliable operationalenvironment.

2. CTE – Common Table Expression

CTE is a neat way of writing complex queries without the use of temp tables or derived tables. CTEitself can be considered a temp table with scope limited to the query. Unlike derived tables which areintermingled with the main query, CTE-s are placed neatly to the top part of the query, greatlysimplifying the main query itself. CTE-s will increase developer’s productivity by introducing “structured programming” into complex queries. Here is an example for a double CTE query where the

second CTE is used to resolve both the employee name and his/her manager's name.

WITH cteEmployeeOrders(EmployeeID, NumOrders, MaxDate)AS(SELECT EmployeeID, COUNT(*), MAX(OrderDate)FROM Purchasing.PurchaseOrderHeaderGROUP BY EmployeeID),cteEmployeeName(Employee, Employeeid)AS(SELECT LastName+', '+ FirstName, Employeeid

FROM HumanResources.Employee EJOIN Person.Contact CON E.ContactID = C.ContactID)SELECT Employee = EN1.Employee, OrdersTaken=OE.NumOrders,LastOrderDate=OE.MaxDate,Manager = EN2.Employee, OrdersTaken=OM.NumOrders,LastOrderDate = OM.MaxDateFROM HumanResources.Employee AS EJOIN cteEmployeeOrders AS OEON E.EmployeeID = OE.EmployeeIDLEFT OUTER JOIN cteEmployeeOrders AS OMON E.ManagerID = OM.EmployeeIDJOIN cteEmployeeName EN1

ON E.EmployeeID = EN1.EmployeeIDJOIN cteEmployeeName EN2ON E.ManagerID = EN2.EmployeeID 

3. Column Headers to Clipboard When Copying Results

How many times you had to produce an ad-hoc report and copy the results window into an Excelspreadsheet? Except the column headers did not come. If the report was destined to high circles, youhad to manually type in 20 column headers?

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 8/10

With SQL 2005 you can turn on the option to include column headers when copying to clipboard.

4. ROW_NUMBER() Function

This solves a problem and more which in a curious way related to 3. In SQL 2000 results window you

could the row sequence numbers on the frame, but again, those did not make it to the clipboard. InSQL 2005 you can generate row numbers for the entire results set or for partitions within the resultsset. Oracle had this feature for sometime. Here is an example:

SELECT 'Row Number' = ROW_NUMBER()OVER(ORDER BY SalesYTD DESC),c.FirstName, c.LastName,SalesYTD = '$'+convert(varchar,s.SalesYTD,1),

a.PostalCodeFROM Sales.SalesPerson sJOIN Person.Contact cON s.SalesPersonID = c.ContactIDJOIN Person.Address aON a.AddressID = c.ContactID

WHERE TerritoryID IS NOT NULLAND SalesYTD <> 0 

5. Tree Processing Functions

Probably you did not need tree processing many times during your database development career, butwhen you needed it, you really needed it. In lieu of it, you resorted to cumbersome loops going fromlevel to level. Of course, tree processing is built-in into C++ and other object-oriented languages. Nowyou can have it handy in T-SQL when someone asks you to produce an organizational chart. Treeprocessing is associated with the CTE feature. Here is an example. The organizational chart of AdventureWorks mountain bike manufacturing company:

WITH cteOrgTree(EmployeeID, EmployeeName, ManagerID, TreeLevel, SortOrder)AS(SELECT EmployeeID, EmployeeName=FirstName+' '+LastName, ManagerID, 0,CAST(EmployeeID AS VARBINARY(1024))FROM HumanResources.Employee eJOIN Person.Contact cON e.ContactID = c.ContactIDWHERE ManagerID is nullUNION ALLSELECT E.EmployeeID, EmployeeName=FirstName+' '+LastName, E.ManagerID, M.TreeLevel+1,CAST(SortOrder + CAST(E.EmployeeID AS BINARY(4)) AS VARBINARY(1024))FROM HumanResources.Employee AS EJOIN cteOrgTree AS M

ON E.ManagerID = M.EmployeeIDJOIN Person.Contact CON E.ContactID = C.ContactID)SELECTREPLICATE(' | ', TreeLevel)+ '(' + (CAST(EmployeeID AS VARCHAR(10))) + ') '+ EmployeeName AS EmployeeNameFROM cteOrgTreeORDER BY SortOrder 

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 9/10

 6. Native XML

The XML integration will surely give a boost in the proliferation of XML as a data format standard.Example for an XQUERY:

SELECT CatalogDescription.query('declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";for $pd in /p1:ProductDescription,$f in $pd/p1:Features/*return<Feature><ProductModelName> { data($pd/@ProductModelName) } </ProductModelName>{ $f }</Feature>') as FeatureFROM Production.ProductModelWHERE ProductModelID=25 

7. The OUTPUT Clause

Not a very fancy feature, but extremely useful for setting up auditing and logging. It essentially makesthe inserted and deleted tables available in the query itself, without resorting to the use of a trigger.Here is an example:

SELECT *INTO CopyOfEmployeeFROM HumanResources.EmployeeGODECLARE @DeletedEmployees TABLE

(EmployeeID INT)WHILE (2 > 1) 

BEGINBEGIN TRANDELETE TOP(10) FROM CopyOfEmployeeOUTPUT deleted.EmployeeIDINTO @DeletedEmployees

WHERE HireDate < '2003-02-02'SELECT * FROM @DeletedEmployeesCOMMIT TRANDELETE FROM @DeletedEmployees

IF @@rowcount < 10BREAKEND 

8. PIVOT

How many times management came to you for an ad-hoc cross-tab report. You had no choice butsetup a temporary table and fill it up or use ackward CASE construct with heavy hard wiring toproduce it. PIVOT solves this issue partially, dynamic PIVOT solves it even better. Here is an example:

8/2/2019 10 Developer Features Introduced in SQL Server 2008

http://slidepdf.com/reader/full/10-developer-features-introduced-in-sql-server-2008 10/10

 SELECT pvt.*FROM(SELECT PurchaseOrderID, EmployeeID, VendorIDFROM Purchasing.PurchaseOrderHeader) pPIVOT(

COUNT (PurchaseOrderID)FOR EmployeeID in ([274],[238],[241],[223],[264],[266],[231],[244],[261],[233],[164],[198])) AS pvt

ORDER BY VendorID 

9. Schemas

The idea is that a schema should own db objects since the schema never leaves the company unlikepeople, especially IT people. SQL Server always had a schema, the infamous "dbo". Another way of looking at schemas is as convenient prefixes for a group of tables. A major shortcoming is that theschemas are single level. In a large database with over 3,000 tables, one would need multi-levelschemas. Perhaps that feature is coming with SQL Server 2010.

10. Ranking and Tiling Functions

You can produce tons of Business Intelligence reports using these functions. The more you produce,the more will be requested. Here is an example:

SELECT ProductName = Name, Color, ListPrice,ROW_NUMBER() OVER(ORDER BY ListPrice DESC) AS SeqNo,NTILE(6) OVER(ORDER BY ListPrice DESC) AS Sextile,RANK() OVER(ORDER BY ListPrice DESC) AS RankFROM Production.ProductORDER BY ListPrice DESC