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…
“Approve” Multiple records in a GridView
Every once in a while you have a list of records that need to be “approved by a manager.” You could select the records via a filter, but that always gets a little cumbersome because there’s always one record you…
SQL – Creating and Dropping Temp Tables
I run into this all the time but can’t ever remember the syntax. First, check to see if it exists and if it does, drop it. IF OBJECT_ID(‘tempdb..#MyTempTable’) IS NOT NULL Drop Table #MyTempTable Second, build your table. The “#”…
Navigating Excel Cells in VBA
Fixed Reference There’s plenty of documentation on how to move around Excel in VBA if you know exactly what cell you want to move to. For example to move to cell D3 all you need to do is add this…
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…
Care and Feeding of SQLParameters and SQLHelper
I chased my tail for hours on this one, but finally found the combination that works. Here’s the basic layout Function GetProjects(ID as int64, Name as string) Dim arParams As SqlParameter() = New SqlParameter(2) {} arParams(0) = New SqlParameter(“@ID”, IIf(ID…