DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to use CROSS APPLY to increase company profits?

Execute the following Microsoft SQL Server Transact-SQL (T-SQL) script in Management Studio (SSMS) Query Editor to identify all the stores which did not place an order in the last 30 days or the order was less than $10,000.00:

USE AdventureWorks

 

GO

 

CREATE FUNCTION Sales.LastOrder

               (@CustID AS INT)

RETURNS TABLE

AS

  RETURN

    SELECT   TOP ( 1 ) SalesOrderID,

                       OrderDate,

                       OrderTotal = TotalDue

    FROM     Sales.SalesOrderHeader

    WHERE    CustomerID = @CustID

    ORDER BY OrderDate DESC

 

GO

 

SELECT Customer = Name,

       lo.SalesOrderID,

       lo.OrderDate,

       TotalDue = '$' + convert(VARCHAR,lo.OrderTotal,1)

FROM   Sales.Store

       CROSS APPLY Sales.LastOrder(CustomerID) AS lo

WHERE  datediff(DAY,OrderDate,getdate()) > 30

        OR OrderTotal < 10000

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE