Você está na página 1de 3

--Day 1 USE AdventureWorks; GO SELECT YEAR(poh.OrderDate) * 100 + MONTH(poh.OrderDate) AS OrderMonth ,pc.Name AS ProductCategory ,psc.Name AS ProductSubCategory ,p.Name ,SUM(pod.

OrderQty) AS OrderQty ,SUM(pod.LineTotal) AS Amount FROM Production.ProductCategory AS pc INNER JOIN Production.ProductSubcategory AS psc ON pc.ProductCategoryID = psc.ProductCategoryID INNER JOIN Production.Product AS p ON psc.ProductSubcategoryID = p.ProductSubcategoryID INNER JOIN Purchasing.PurchaseOrderDetail AS pod ON p.ProductID = pod.ProductID AND p.ProductID = pod.ProductID INNER JOIN Purchasing.PurchaseOrderHeader AS poh ON pod.PurchaseOrderID = poh.PurchaseOrderID AND pod.PurchaseOrderID = poh.PurchaseOrderID GROUP BY pc.Name ,psc.Name ,p.Name ,YEAR(poh.OrderDate) * 100 + MONTH(poh.OrderDate) ORDER BY ProductCategory, ProductSubCategory, p.Name, OrderMonth; GO --Day 2 USE AdventureWorks; GO SELECT YEAR(sh.ShipDate) AS Year ,DATEPART(Month, sh.ShipDate) AS MonthNumber ,DATENAME(Month, sh.ShipDate) AS Month ,sm.Name ,sod.CarrierTrackingNumber ,SUM(sod.OrderQty) AS Quantity ,SUM(sod.LineTotal) AS Amount FROM Sales.SalesOrderDetail AS sod INNER JOIN Sales.SalesOrderHeader AS sh ON sod.SalesOrderID = sh.SalesOrderID INNER JOIN Purchasing.ShipMethod AS sm ON sh.ShipMethodID = sm.ShipMethodID GROUP BY sm.Name ,YEAR(sh.ShipDate) ,DATEPART(Month, sh.ShipDate) ,DATENAME(Month, sh.ShipDate) ,sm.Name ,sod.CarrierTrackingNumber ORDER BY Year, MonthNumber, sm.Name, sod.CarrierTrackingNumber; GO -- Query for the Logistic report with parameters SELECT YEAR(sh.ShipDate) AS Year ,DATEPART(Month, sh.ShipDate) AS MonthNumber ,DATENAME(Month, sh.ShipDate) AS Month ,sm.Name

,sod.CarrierTrackingNumber ,SUM(sod.OrderQty) AS Quantity ,SUM(sod.LineTotal) AS Amount FROM Sales.SalesOrderDetail AS sod INNER JOIN Sales.SalesOrderHeader AS sh ON sod.SalesOrderID = sh.SalesOrderID INNER JOIN Purchasing.ShipMethod AS sm ON sh.ShipMethodID = sm.ShipMethodID WHERE YEAR(sh.ShipDate) = @Year AND MONTH(sh.ShipDate) = @Month GROUP BY sm.Name ,YEAR(sh.ShipDate) ,DATEPART(Month, sh.ShipDate) ,DATENAME(Month, sh.ShipDate) ,sm.Name ,sod.CarrierTrackingNumber ORDER BY Year, MonthNumber, sm.Name, sod.CarrierTrackingNumber; GO -- Distinc years dataset SELECT DISTINCT YEAR(sh.ShipDate) AS Year FROM Sales.SalesOrderHeader AS sh ORDER BY YEAR(sh.ShipDate); GO -- Months dataset SELECT DISTINCT MONTH(sh.ShipDate) AS MonthNumber ,DATENAME(Month, sh.ShipDate) AS MonthName FROM Sales.SalesOrderHeader AS sh WHERE YEAR(sh.ShipDate)=@Year ORDER BY MONTH(sh.ShipDate); GO -- Query for the products and stock levels SELECT ProductNumber ,Name ,Color ,SafetyStockLevel ,ReorderPoint ,ListPrice ,CAST(SafetyStockLevel * (RAND(CHECKSUM(NEWID())%1000000000)+0.5) AS int) AS StockLevel FROM Production.Product WHERE FinishedGoodsFlag=1; GO --Day 3 --product number, name, safety stock level, stock level USE AdventureWorks; SELECT ProductNumber ,Name ,Color ,SafetyStockLevel ,ReorderPoint ,ListPrice ,CAST(SafetyStockLevel * (RAND(CHECKSUM(NEWID())%1000000000)+0.5)

AS int) AS StockLevel FROM Production.Product WHERE FinishedGoodsFlag=1; --VB Code Function GetStockColor(ByVal Stock AS Short, ByVal Level AS Short) As String Dim returnValue As String returnValue = "" Select Case (100*Stock)/Level Case Is < 80 returnValue = "Red" Case Is < 100 returnValue = "Yellow" Case Is >= 100 returnValue = "Green" End Select Return returnValue End Function --Call on the color property of the text box =Code.GetStockColor(Fields!StockLevel.Value, Fields!SafetyStockLevel.Value)

----------------------------------------------------------------Function GetQuantityColor(ByVal Quantity AS Short) As String Dim returnValue As String returnValue = "" Select Case (Quantity) Case Is < 500 returnValue = "blue" Case Is < 100 returnValue = "Yellow" Case Is >= 500 returnValue = "Green" End Select Return returnValue End Function ---------------------------------------=Code.GetQuantityColor(Fields!OrderQty.Value)

Você também pode gostar