Jump to content

T-SQL to get numbers between 1 and n?


stuartmarsh

Recommended Posts

Hi All,

I don't know if this is simple or not, but I'd like some SQL to return a number of sequential values starting at a number I specify.

For example, I want to start at 5 for 5 iterations.

The result I would like back would be

Numbers
5
6
7
8
9

 

Thanks.

Hrmmm...  Why do you want to do this?  Why not just use what ever language you're pulling the data into?

 

 

If you're trying to select things between something, you can do WHERE x >= 5 AND x < 10  (not sure if MSSQL has BETWEEN or not).

I have some SQL that gets the current week number based on today's date I.e 200940.

Based on that I want to get the last n weeks, so ultimately I have a SQL that gives me

WeekNo
200940
200939
200938
200937

I could do this with a loop in PHP but I'm trying to do it in the SQL if possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.