Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need To Create A List Of Sequential Up To a Value

Author  Topic 

KevMull
Starting Member

11 Posts

Posted - 2007-04-05 : 06:55:20
I have a value ('MyValue') stored in a single row table ('MyTable')

I need to generate a view, sp etc that will give me a list of numbers starting at 1 and then finish at the above 'Myvalue'.

How Can I do this ?

Many Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-05 : 07:05:23
TSEOSD Please!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 07:23:42
quote:
Originally posted by harsh_athalye

TSEOSD Please!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


What does it mean?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-05 : 07:59:01
It means Table Structures, Expected Output and Sample Data please!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

KevMull
Starting Member

11 Posts

Posted - 2007-04-05 : 08:16:40
I just need a script to generate a list (rows in view) of sequential numbers starting at 1 and ending at [MyField] FROM 'MyTable'.
So if 'MyField' =5 then the view or SP would look like this..
1
2
3
4
5

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-05 : 09:09:31
1) SELECT Number FROM F_NUMBER_RANGE(1, 5)
2) SELECT Number FROM master..spt_values WHERE Name IS NULL AND Number BETWEEN 1 AND 5


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

KevMull
Starting Member

11 Posts

Posted - 2007-04-05 : 09:23:52
Thanks Peso, but i don't follow any of that .
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 23:32:09
quote:
Originally posted by KevMull

Thanks Peso, but i don't follow any of that .



Why?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 23:34:09
quote:
Originally posted by harsh_athalye

It means Table Structures, Expected Output and Sample Data please!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"

I see. When did you introduce this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-05 : 23:35:09
quote:
Originally posted by KevMull

Thanks Peso, but i don't follow any of that .



have you tried Peter's 2nd suggestion ?


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 23:59:39
quote:
Originally posted by khtan

quote:
Originally posted by KevMull

Thanks Peso, but i don't follow any of that .



have you tried Peter's 2nd suggestion ?


KH



No I didnt

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-06 : 00:00:24
quote:
Originally posted by madhivanan

quote:
Originally posted by khtan

quote:
Originally posted by KevMull

Thanks Peso, but i don't follow any of that .



have you tried Peter's 2nd suggestion ?


KH



No I didnt

Madhivanan

Failing to plan is Planning to fail


I did.


KH

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-04-06 : 09:28:44
Why does everyone keep giving solutions with F_NUMBER_RANGE()? Is that a system function? If not, then maybe it would be helpful to explain to people what it is and where to find it?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -