Friday, October 31, 2008

Using group by the right way

Here are two great articles about the usage of Group By:

SQL GROUP BY techniques
More on GROUP BY; Examining SUM(Distinct)

Thanks to Jeff Smith.

In a nut-shell, instead of this:


SELECT
C.CustomerID, C.CustomerName,
C.CustomerType, C.Address1, C.City,
C.State, SUM(S.Sales) as TotalSales
FROM
Customers C
INNER JOIN Sales S
ON C.CustomerID = S.CustomerID
GROUP BY
C.CustomerID, C.CustomerName,
C.CustomerType, C.Address1, C.City, C.State

Use this:


SELECT
C.CustomerID, C.CustomerName,
C.CustomerType, C.Address1, C.City,
C.State, S.TotalSales
FROM
Customers C
INNER JOIN
(SELECT
CustomerID, SUM(Sales) as TotalSales
FROM
Sales
GROUP BY
CustomerID) S
ON
C.CustomerID = S.CustomerID


This way you don’t need to include bunch of fields in your group by clause unnecessarily.

Wednesday, October 15, 2008

How to find out which process is locking a DLL

1- Start->Run and Open Cmd box
2- Type and execute the following
tasklist /m mydll.dll

and it will return a process list that have loaded your DLL!

Cool ha!

"tasklist /?" will give you a list of other things you can do with this utility.