Friday, February 5, 2010

SQL Server 2005: Creating a View

Another day at work:
Let's say your boss wants to see orders with a line total less than $5. He is planning on writing up the Sales people who have made such orders. He just wants the line total.

Hint: The table used is sales.salesorderdetail.

In a New Query type:

USE AdventureWorks
Select
SalesOrderID, LineTotal

FROM
Sales.SalesOrderDetail

WHERE
LineTotal

Order by LineTotal

Execute and you will see two columns the SalesOrderID and the LineTotal. The Line Total will be ordered (sorted) least to greatest because of the "Order by" command.
If you want to know more about views see The Code Project article about Views.

No comments: