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.
| Author |
Topic |
|
mike13
Posting Yak Master
219 Posts |
Posted - 2009-10-22 : 09:38:42
|
| Hi all,I want to insert into a table these values:970000000970000001970000002970000003970000004970000005........like 10.000 like that.what is the easiest way to achieve this?Thanks a lot,Mike |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-22 : 09:46:48
|
I would do it this way:-- making a testtabledeclare @table table(number int)-- testsolution with 10 loopsdeclare @loop intset @loop=0while @loop < 10begin insert @table select 10000+@loop set @loop=@loop+1end-- show resultselect * from @table No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-10-22 : 09:50:19
|
| create table #temp (number int)declare @i intset @i=0while (@i<=10)Begininsert into #tempselect 970000000+@i set @i=@i+1Endselect * from #tempSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-22 : 10:02:51
|
| -- test solution with 10 recursions;with number(n)as(select 1 as nunion allselect n+1 from number where n<10)-- show resultselect 970000000+n from numberMadhivananFailing to plan is Planning to fail |
 |
|
|
mike13
Posting Yak Master
219 Posts |
Posted - 2009-10-22 : 15:21:08
|
| thanks webfred that did the trick ;-) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-23 : 04:16:13
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
StevePD
Starting Member
2 Posts |
Posted - 2009-10-23 : 22:29:16
|
| Hey!I would simply use a simple cursor, see example @http://sites.google.com/site/sqlsimple/home/solutionsor for a more complex example, showing how to possibly integrate your cursor, check out:"List all databases, table/views, columns, their data types and maximum lengths" on the same page, it uses the same logic.StevePD |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-24 : 05:56:43
|
cursor - pah! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|