I need to write some TSQL that will return to me the total number of Mondays, tuesdays, wednesdays, thursdays, fridays, saturdays and sundays in a given date period. It needs to be as efficient as possible. What is the best way to do this?
create function ufn_get_days(@d1 datetime, @d2 datetime, @day int)
returns int as
abs(datediff(d, @d1, @d2)/7) -- 1 day per full week
+ case when abs(datediff(d, @d1, @d2)%7) >= (15+@day-@@datefirst-datepart(dw,
With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied?
You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.