Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Last Sunday Expand / Collapse
Author
Message
Posted Monday, May 11, 2009 7:33 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 6:06 AM
Points: 247, Visits: 243
Comments posted to this topic are about the item Last Sunday
Post #714098
Posted Wednesday, August 19, 2009 8:42 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 6:06 AM
Points: 192, Visits: 164
The function below returns the week ending date for the specified week day.

-- =============================================
-- Author: Barkha Javed
-- Create date: 10 Jul 2009
-- Description: Date of week ending, per given weekday
-- =============================================

ALTER FUNCTION [dbo].[fn_LastWeek]
( @Duration int,
@DayOfWeek varchar(10) = Null
)

RETURNS nchar(8)
AS
BEGIN
DECLARE @dt nchar(8)
DECLARE @DiffDays int

SELECT @DiffDays = CASE WHEN @DayOfWeek Like 'Mon%' THEN '2'
WHEN @DayOfWeek Like 'Tue%' THEN '3'
WHEN @DayOfWeek Like 'Wed%' THEN '4'
WHEN @DayOfWeek Like 'Thu%' THEN '5'
WHEN @DayOfWeek Like 'Fri%' THEN '6'
WHEN @DayOfWeek Like 'Sat%' THEN '7'
WHEN @DayOfWeek Like 'Sun%' THEN '1'
ELSE '1' END

SELECT @dt = Convert(nchar(8),DateAdd(d, -(DatePart(w, getdate())-@DiffDays), DateADD(wk, @Duration, getdate())),1)

RETURN @dt

END
Post #773582
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse