| Author |
Topic  |
|
|
SQLMAKESMECRY
Starting Member
14 Posts |
Posted - 03/23/2011 : 09:23:33
|
Is there a way to create a list of every day of the year by using only today's date and some future date? or some number of days in the future?
Cricket
It's not fun unless I'm pulling my hair out. Weee!
http://strattenramble.blogspot.com/ |
Edited by - SQLMAKESMECRY on 03/23/2011 09:26:17
|
|
|
jimf
Flowing Fount of Yak Knowledge
USA
2868 Posts |
Posted - 03/23/2011 : 09:33:58
|
Actually, there are several ways
select dateadd(day,number,'20110101') from master..spt_values where type = 'p'
Others are more clever, but this works for me.
Jim
Everyday I learn something that somebody else already knew |
 |
|
|
SQLMAKESMECRY
Starting Member
14 Posts |
Posted - 03/23/2011 : 09:42:40
|
quote: Originally posted by jimf
Actually, there are several ways
select dateadd(day,number,'20110101') from master..spt_values where type = 'p'
Others are more clever, but this works for me.
Jim
Everyday I learn something that somebody else already knew
Wow that is a simple one! Thank you! What database is MAster..spt_values? Is that what its doing? creating a virtual database or is that something in sql that I don't know about?
Cricket
It's not fun unless I'm pulling my hair out. Weee!
http://strattenramble.blogspot.com/ |
 |
|
|
robvolk
Most Valuable Yak
USA
15559 Posts |
Posted - 03/23/2011 : 10:01:37
|
master is the main system database for SQL Server, most of the system configuration and procedures are stored there. You should take some time to look around it and get familiar with it, just make sure not to modify anything in it.
Books Online describes what master does in more detail. |
 |
|
|
jimf
Flowing Fount of Yak Knowledge
USA
2868 Posts |
Posted - 03/23/2011 : 10:01:56
|
spt_values is a system table in the master database that has various numbers in it, you get 2048 of them for type'P' (0 - 2047)
select * from master.dbo.spt_values
Jim
Everyday I learn something that somebody else already knew |
 |
|
|
SQLMAKESMECRY
Starting Member
14 Posts |
|
|
sandeepmittal11
Starting Member
India
6 Posts |
|
|
ScottPletcher
Yak Posting Veteran
USA
79 Posts |
Posted - 12/21/2012 : 17:33:56
|
quote: Originally posted by jimf
spt_values is a system table in the master database that has various numbers in it, you get 2048 of them for type'P' (0 - 2047)
select * from master.dbo.spt_values
Jim
Everyday I learn something that somebody else already knew
As of today, you get values 0-2047 for type 'P'. You have NO idea if this will be true for the next upgrade to SQL, or if this table will even exist in future versions.
It's far better to use your own in-line CTE to generate numbers "on the fly" or pre-build your own physical tally table and use it. It's extremely poor practice to use something that could easily cause missing data at the next SQL upgrade! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47088 Posts |
|
| |
Topic  |
|