• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Create List/sequence from nothing e.g. 1,2,3,4,5,.....,99,100

How can i create a sequence of numbers or dates from nothing! i.e. i want a list of numbers 1 to 100 without referencing a table.

0
leatham
Asked:
leatham
  • 3
  • 3
  • 2
1 Solution
 
m1tk4Commented:
If you just need them to be a part of WHERE clause (because that's the only case where I see NOT wanting a table to make sense) you can do

select * from mytable where myfield in (1,2,3,4,5,6,7,8,9,10 ..and so on... 99,100);
0
 
leathamAuthor Commented:
I have some very heafty queries that i need to run based on a list of dates. at the moment i use a table that has a list of dates and i simply join the dates table to a subquery of the main query to limit the amount of data that is being retrieved.

The problem is that anyone running this query is limited to the dates in the table. I want one user to be able to run the query based on a different set of dates from the an other user at the same time.

If i can know how to run a series of numbers then i can generate the dates. what is the 'in' part of your query do?

Thanks
0
 
m1tk4Commented:
(myfield in (1,2,3)) will return a boolean true if myfield=2 and boolean false if myfield=4. You can do the same with dates instead of integers.

Now, your list of dates - what is it really, list of working days, all tuesdays, something else? Maybe you can work out a common rule to describe the dates you are interested in instead of using a "table function".
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
leathamAuthor Commented:
I simply need a list if consecutive dates. I know how to filter a list, i was just wondering if this was possible without referencing a table.
0
 
m1tk4Commented:
if they are consecutive, why can't you use

(d between startDate and endDate)

?
0
 
earth man2Commented:
select generate_series(1,20,2), to_date('29-JAN-2002','DD-MON-YYYY') + generate_series(1,147,7);
0
 
earth man2Commented:
select generate_series(1,100);
0
 
earth man2Commented:
I need to read the docs before I give you bad information...

select * from generate_series(1,100);

select current_date + s.a as dates from generate_series(0,14,7) as s(a);

http://www.postgresql.org/docs/8.1/static/functions-srf.html
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now