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 |
cidr
Posting Yak Master
207 Posts |
Posted - 2009-09-08 : 05:30:09
|
Hi there,I have a (potentially simple) problem but I don't seem to be able to get round.I have a table, similar to a numbers table but has dates in there. There's a Weekstart and WeekEnd column all dates start on a Sunday and end on a Saturday.There is also a numbers column with the week number from 1 - 52.I'm trying to run the code below so that it picks the last week number, last week number being 35. When I run the code it gives me 52. Does anyone know how I can alter the code so that it picks up 35.Any help is always appreciated.Thanks select (fld_WeekNo) 'LastWeekNo' from dbo.tblWeekNo with (nolock) where WeekEndDate + 1 < getdate() |
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-09-08 : 06:37:34
|
select MAX(fld_WeekNo) FROM dbo.tblWeekNo with (nolock)where WeekEndDate + 1 < getdate();Rahul Shinde |
|
|
cidr
Posting Yak Master
207 Posts |
Posted - 2009-09-08 : 07:25:02
|
Thanks ra.shinde for getting back to me.I really messed up this thread, the code already had MAX in it but I took it out by mistake.The problem I had was the end date was picking up 52 because < getdate was picking up the previous year's last date (which was 52)Now that I know what happened it would have been appropriate for me to add that there is a year column and I've used YearDate = Year(getdate()) to the code to only pick up the last MAX date of the current year (which is 35)Thanks again |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-09-08 : 07:37:03
|
quote: Originally posted by cidr Thanks ra.shinde for getting back to me.I really messed up this thread, the code already had MAX in it but I took it out by mistake.The problem I had was the end date was picking up 52 because < getdate was picking up the previous year's last date (which was 52)Now that I know what happened it would have been appropriate for me to add that there is a year column and I've used YearDate = Year(getdate()) to the code to only pick up the last MAX date of the current year (which is 35)Thanks again
Rahul Shinde |
|
|
|
|
|