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
 General SQL Server Forums
 New to SQL Server Programming
 Generate rows automatically

Author  Topic 

FDumestani
Starting Member

1 Post

Posted - 2007-09-27 : 06:04:21
Hi,

How can I generate rows automatically?

The number of rows is generated according to an input from the user!

Thanks,

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-27 : 06:11:59
make use of F_TABLE_NUMBER_RANGE from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47685&SearchTerms=F_TABLE_NUMBER_RANGE

or just simply use a while loop


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-27 : 06:28:29
quote:
Originally posted by FDumestani

Hi,

How can I generate rows automatically?

The number of rows is generated according to an input from the user!

Thanks,


Why do you want to do this?

Madhivanan

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

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-09-27 : 07:12:49
Why ask why?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-28 : 02:07:50
quote:
Originally posted by DonAtWork

Why ask why?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


To know why OP wants to do it

Madhivanan

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

renu
Starting Member

47 Posts

Posted - 2007-09-28 : 02:25:13
declare @v int,@v1 varchar(1000)

set @v=2


set @v1='select top '+ cast(@v as varchar(100)) +' * from tablename'
exec(@v1)
Go to Top of Page

renu
Starting Member

47 Posts

Posted - 2007-09-28 : 02:25:49
is this u expect
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-28 : 03:02:00
quote:
Originally posted by renu

declare @v int,@v1 varchar(1000)

set @v=2


set @v1='select top '+ cast(@v as varchar(100)) +' * from tablename'
exec(@v1)


If that is the case, you can avoid dynamic sql

declare @v int

set @v=2

Set Rowcount @v

select * from tablename

Set Rowcount 0



Madhivanan

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

renu
Starting Member

47 Posts

Posted - 2007-09-28 : 04:35:18
ya its more simple
Go to Top of Page
   

- Advertisement -