| Author |
Topic |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-10-25 : 14:51:54
|
| say i have a week number : 2 which means the first day of the weeks date is : 8/1 and the last 1 is : 14/1how can i do this in SQL?Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-10-25 : 15:12:03
|
That depends on things like what year you're in and what day you want to treat as the first day of the week, but here's an example of the general ideadeclare @WeekNo intdeclare @StartYear datetimeset @WeekNo = 2set @StartYear = '1/1/2006'select dateadd(ww, @WeekNo - 1, @StartYear), dateadd(dd, -1, dateadd(ww, @WeekNo, @StartYear)) |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-10-25 : 15:13:05
|
| You can read all about the different functions available to manipulate dates in Books Online.The "+" operator is overridden for datetime types to add days ... so 20060101 + 7 = 20060108. You should be able to take if from there.Your sig makes no sense.Jay White |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-10-26 : 01:52:24
|
quote: Your sig makes no sense.
and why is that?i dont want to get much to politics but there are pepole here belive that if they blow up kids with bobms 72 virgins will wait for them in heaven so if is the truth (as they belive) why not every one runs to heaven>?Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-10-26 : 08:47:53
|
| I'm not commenting on your politics. As far as I'm concerned you can sig whatever you want.Look, I'm a shitty speller and my grammer sucks, too ... but for something like a sig, which appears 264 (and counting) times on this site, I would think you would at least want it to be readable. aftr ... ok, I translate that to after ... 9but ... ok, I'm guessing the 9 was fat fingered ... wan't ... could this be wants ... or wouldn't ... I have no idea. That's where you loose me. Is Isreal where you suggest we go after we've been to heaven or are you saying Isreal is the second best and heaven is the best? And who is going where fast, heaven or Isreal?Jay White |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-10-26 : 09:41:56
|
says to me : Israel is the best place to live (besides heaven), but nobody wants to go to heaven any time soon( i.e. die)At least, that is the most sense i can make out of it. My english sucks too, but i have an excuse. I am an American [Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-10-26 : 09:51:54
|
quote: Originally posted by pelegk2
quote: Your sig makes no sense.
and why is that?i dont want to get much to politics but there are pepole here belive that if they blow up kids with bobms 72 virgins will wait for them in heaven so if is the truth (as they belive) why not every one runs to heaven>?Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
OK, so how about filling us in on what you want to do in SQL if you need some help?I couldn't tell from your post waht you want to do. If you want something to do with week number, you need to explain what your definition of week number is.CODO ERGO SUM |
 |
|
|
samuelclay
Yak Posting Veteran
71 Posts |
Posted - 2006-10-26 : 13:59:25
|
| Yeah, not very clear what is needed.. for a given week, the start day is 1+7*(@WeekNum-1) and the end day is 7*@WeekNumwith the exception of week 5 which would be dependant of the month(and possibly year).. (0 or 1 days for feb depending on year, 2 days for apr, jun, sep, nov, 3 days for remaining...) |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-10-26 : 14:22:42
|
quote: Originally posted by samuelclay Yeah, not very clear what is needed.. for a given week, the start day is 1+7*(@WeekNum-1) and the end day is 7*@WeekNumwith the exception of week 5 which would be dependant of the month(and possibly year).. (0 or 1 days for feb depending on year, 2 days for apr, jun, sep, nov, 3 days for remaining...)
You're making guesses there. They could be using ISO weeks. They could be weeks related to fiscal year. They could be just 7 day periods starting from Jan 1...I am amazed at the number of people that post questions about weeks here and seem to never be able to explain this clearly. I believe this is the second time he has posted this question recently, and the second time I have asked him this question with no clear answer.CODO ERGO SUM |
 |
|
|
samuelclay
Yak Posting Veteran
71 Posts |
Posted - 2006-10-26 : 14:33:59
|
| True, I was guessing based on his definition of week 2. simply an example showing that even with making big assumptions we still don't haven enough information to return relevant data.Should have explained my example a little better... |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-10-26 : 14:51:23
|
Well, I made a big unfounded assumption that the OP will understand and answer my question. CODO ERGO SUM |
 |
|
|
|