SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Last Sunday


Last Sunday

Author
Message
barkha.javed
barkha.javed
SSC Veteran
SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)SSC Veteran (267 reputation)

Group: General Forum Members
Points: 267 Visits: 255
Comments posted to this topic are about the item Last Sunday
Javed-330570
Javed-330570
SSC Veteran
SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)SSC Veteran (200 reputation)

Group: General Forum Members
Points: 200 Visits: 172
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search