July 2010 Entries

Execute a command against all tables in a database

Have you ever wanted to execute a command againts all tables in your database? And did you struggle with cursors or WHILE BEGIN ... END loops? So did I. Until I discovered the undocumented stored procedure sp_MSforeachtable and I love it.

How to calculate working time?

Say you have a time registration system in your plant that registers when people use their badges to check in and out. And say you want to calculate the actual time that people have been present. I had to solve this issue for a SQL Server 2000 database. The solution of course works for newer versions as well and I am very interested in other solutions.