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


SQL Squery- Start day- Monday


SQL Squery- Start day- Monday

Author
Message
var05
var05
Mr or Mrs. 500
Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)

Group: General Forum Members
Points: 527 Visits: 437
Hi All

I have a query to fetch the starting day as "Monday" between any 2 selected dates.

For eg:

Start Date is : 08/12/2012
End Date is 08/19/2012

and I wanted the output as:

Date start of week
08/12/2012 08/06/2012 ----------------that is the Monday
08/13/2012 08/13/2012--------start day Monday
08/14/2012 08/13/2012-Monday
....
08/19/2012 08/13/2012


I use the below query as of now

(select DISTINCT Date_Column,CONVERT(date, DATEADD(wk, DATEDIFF(wk, 0, DATEADD(d, - 1,Date_Column)), 0), 103) AS Week,DATEPART(Week,Date_Column) as Week_Num
from dbo.date_dim
where convert(date,Date_Column,103) BETWEEN
dateadd(wk, datediff(Wk, 0, DATEADD(dd,-1,'08/12/2012')), 0)
AND dateadd(wk, datediff(wk, 0, DATEADD(dd,-1,'08/19/2012')), 0)
)



I know my query returns wrong results...could any 1 please know how to achieve the result.

Thanks
var05
var05
Mr or Mrs. 500
Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)Mr or Mrs. 500 (527 reputation)

Group: General Forum Members
Points: 527 Visits: 437
My where clause should be just between startdate and enddate...but wheras I have use start of week also in the where clause...

I hope wat I had figured out is right..

Thanks
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