Reputation: 981
I have a SQL table with a column that says number of days, and contains entries like 23, 26, 45, etc... I am trying to convert each entry to a "week number". In essence, what I mean is that if my day entry is between 0 and 6, then, this is Week 1, if it is 7 and 13, then this is Week 2, 14 and 20, week 3, etc... Is there an "efficient" way to do this in SQL?
Thanks. Thomas.
Upvotes: 2
Views: 3550
Reputation: 178
You can try this and no need to add +1;
SELECT (Days / 7.00)
Upvotes: 1
Reputation: 1842
You need just the standard divide function. It ignores the remainder:
SELECT (Days / 7) + 1
Upvotes: 6