SQL Server: Group records by Week

Quick code snippet to group a recordset by week.  In this case we are summing hours worked per week. SELECT DATEPART(YEAR,myDateField) AS ‘Year’,            DATEPART(wk,myDateField) AS ‘Week #’,            MIN(DATEADD(wk, DATEDIFF(wk,0,myDateField), 0)) AS ‘Week date’,            SUM(COALESCE([Hours],0)) AS ‘Hours’ FROM…

Orphaned SQL Server Users

The Scenario: You’re working on a SQL database locally and when you restore the database on the  production server the login no longer works.  The user has been orphaned. Solution #1 – Delete and recreate the user from scratch Solution…