Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rollypolly
Starting Member
2 Posts |
Posted - 2010-09-28 : 05:13:20
|
I want to allocate Monday's date to the week running Monday to Sunday in a view. What do you suggest?In the view I am currently trying: DATEADD(d, 1, dbo.GetFirstDayOfWeek(CalendarBase.TheDate)) AS fieldname (function below)ALTER FUNCTION [dbo].[GetFirstDayOfWeek]( @pInputDate DATETIME )RETURNS DATETIMEBEGINSET @pInputDate = CONVERT(VARCHAR(10), @pInputDate, 111)RETURN DATEADD(DD, 1 - DATEPART(DW, @pInputDate),@pInputDate)ENDThat is allocating Monday's date to the week running Sunday to Saturday. I tried to use datefirst with no luckRolly Polly |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-09-28 : 06:48:13
|
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, @pInputDate) / 7 * 7, 0) N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|