MERGE Production.ProductInventory AS [pi]USING ( SELECT ProductID, SUM(OrderQty) AS OrderQty FROM Sales.SalesOrderDetail AS sod INNER JOIN Sales.SalesOrderHeader AS soh ON sod.SalesOrderID = soh.SalesOrderID WHERE soh.OrderDate = GETDATE() GROUP BY ProductID ) AS src (ProductID, OrderQty) ON src.
Read more →
Difference between NOT IN, LEFT JOIN and NOT EXISTS.
The objective is to fetch all records in one table that are not present in another table. The most common code I’ve seen at client sites includes the use of NOT IN, because this keyword is included in most programming languages and programmers tend to use this technique when writing stored procedures in the database too.
Read more →
I recently was given the task to optimize some code prior to a client's upgrade to SQL Server 2005. The objective for the old code was to get all orders where status for all orderlines where set to 'DROP'.
Read more →