Thursday, January 06, 2005

Useful TSQL routines.

remove the time part.
convert(datetime,convert (varchar(6),getdate(),12))

get the weeks monday.
dateadd(day, (DATEPART(dw, @startdate )*-1) +2, @startdate )

get weeks sunday.
dateadd(day, (DATEPART(dw, @enddate )*-1) +8, @enddate )

adding one week for iteration in while loop.
@startdate = dateadd(ww,1,@startdate)

For data within one week (Where clause only)
TblClaytonsJobsDetails.DateToDraw between @startdate and dateadd(d,-1,dateadd(ww,1,@startdate))

0 Comments:

Post a Comment

<< Home