Snippet Alert: Useful dates (eom, bom, etc)

Common date values you may need to reference that you may not want to write from scratch each time.

language-sql  
$CARET$declare @Date date = getdate()
select  
    previous_month_bom =    dateadd(month, datediff(month, 0, @Date) - 1, 0) --previous_month_bom
    ,previous_month_eom =   dateadd(day, -1, dateadd(month, datediff
Posted on

Generate Random Date With Starting Point

If you want to create sample random samples when dealing with date calculations to test your results, you can easily create a start and end point of randomly created dates.

This is a snippet I've saved for reuse:

language-sql

DATEADD(day, (ABS(CHECKSUM(NEWID())) % $Days Seed Value$), '$MinDate$'
Posted on

Finding Groups - Consecutive Months

A step by step explanation on one way to get a consecutive period of months, which could easily be adapted to days, years, or other values.

I'll continue on this track and post a tutorial on eliminating overlapping dates soon.

/*******************************************************
identifying gaps on a month  
*******************************************************/
if object_id('tempdb..#accounts'

Renaming all references inside stored procedures and functions can be migraine worthy without a little help...

If you run across migrating or copying a database structure for some purpose, yet need to change the database references or some other string value inside all the procedures and functions to point to the newly named object, you are in for a lot of work!

I built this procedure