473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Generating a series of numbers or dates?

I want to generate a resultset that is just a series of numbers in
ascending order or perhaps a series of dates.. What I mean is, is
there a way to generate a temporary table of dates given an input of a
start date and an end date.. This table would then contain an entry
for each date in ascending order from the start date to and including
the end date..

Or perhaps with numbers, given a start of 5 and and end of 7
the resulting table would be

5
6
7

Would appreciate any help with this one.. Thanks
Chris
Jul 20 '05 #1
2 3293
The usual technique is just to keep these as permanent tables in your
database and then SELECT numbers and dates out of them as required.

Dates:

CREATE TABLE Calendar
(caldate DATETIME NOT NULL PRIMARY KEY)

INSERT INTO Calendar (caldate) VALUES ('20000101')

WHILE (SELECT MAX(caldate) FROM Calendar)<'20101231'
INSERT INTO Calendar (caldate)
SELECT DATEADD(D,DATEDIFF(D,'19991231',caldate),
(SELECT MAX(caldate) FROM Calendar))
FROM Calendar

Numbers:

CREATE TABLE Numbers
(num INTEGER PRIMARY KEY)

INSERT INTO Numbers VALUES (1)

WHILE (SELECT MAX(num) FROM Numbers)<8192
INSERT INTO Numbers
SELECT num+(SELECT MAX(num) FROM Numbers)
FROM Numbers

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2
Refer to:
http://www.bizdatasolutions.com/tsql/tblnumbers.asp

--
-- Anith
( Please reply to newsgroups only )
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: YS Sze | last post by:
If you know the exact longitude and latitude for a specific location, would anyone think it'd make any sense to find out if this set of location numbers is really part of the Fibonacci series or...
5
by: Henry | last post by:
Dear all, Is there any DB2 SQL statement that could generate rows of intermediate dates by providing the start and end dates?? If 2006-1-1 and 2006-1-31 are provided to the SQL, the output...
4
by: geoffp | last post by:
I need to generate reproducible random number series. I've done the obvious - use mt_srand with the same seed. This supposedly will create the same series every time. Is this true? Its not...
8
by: srinpraveen | last post by:
I know to write a program to print the fibonacci series. But the problem is my teacher has asked us to write a program to print the natural numbers that are not involved in the fibonacci series. For...
8
by: kiranchahar | last post by:
Hey all, How do I generate random numbers with Uniform distribution Uniform(a,b) using C-programming? I want to generate uniform random numbers which have mean following Uniform(p,q) and also...
6
by: BBands | last post by:
Good morning, I store time series data in a SQL database. The results of a typical query using pyodbc look like this. Date Close "2007-01-17" 22.57 Where Date is a datetime.date...
6
by: Mike P | last post by:
I am generating 12 random strings and my code works fine when I step through, but when I then let it run without stepping through and populate a listbox with the array I am building, I get the same...
2
by: J-Burns | last post by:
Hello. Got a problem here. Ive got a set of points tht id be plotting. Those points would contain the date on which the work was done against its frequency. Supposedly if i did something on the...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.