Author |
Topic |
SQLMAKESMECRY
Starting Member
14 Posts |
Posted - 2011-03-23 : 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?CricketIt's not fun unless I'm pulling my hair out. Weee!http://strattenramble.blogspot.com/ |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-23 : 09:33:58
|
Actually, there are several waysselect dateadd(day,number,'20110101')from master..spt_valueswhere type = 'p'Others are more clever, but this works for me.JimEveryday I learn something that somebody else already knew |
|
|
SQLMAKESMECRY
Starting Member
14 Posts |
Posted - 2011-03-23 : 09:42:40
|
quote: Originally posted by jimf Actually, there are several waysselect dateadd(day,number,'20110101')from master..spt_valueswhere type = 'p'Others are more clever, but this works for me.JimEveryday 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?CricketIt's not fun unless I'm pulling my hair out. Weee!http://strattenramble.blogspot.com/ |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-03-23 : 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
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-23 : 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_valuesJimEveryday I learn something that somebody else already knew |
|
|
SQLMAKESMECRY
Starting Member
14 Posts |
Posted - 2011-03-23 : 10:06:43
|
Thank you both. :)CricketIt's not fun unless I'm pulling my hair out. Weee!http://strattenramble.blogspot.com/ |
|
|
sandeepmittal11
Starting Member
6 Posts |
Posted - 2012-12-18 : 01:53:40
|
Refer this link[url]http://itdeveloperzone.blogspot.in/2012/11/generate-list-of-dates-in-sql-server.html[/url]Regards,SandeepMy Blog : http://itdeveloperzone.blogspot.in |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2012-12-21 : 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_valuesJimEveryday 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
52326 Posts |
|
|