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
 Commit problem

Author  Topic 

ConradK
Posting Yak Master

140 Posts

Posted - 2010-09-12 : 15:52:06
create table #crazy
(hi varchar(max))
declare @x int
set @x = 1

while @x < 5


insert into #crazy
select cast(@X as varchar) + CAST(getdate() as varchar)
set @x = @x+1


What the he$$ is WRONG with this?

ConradK
Posting Yak Master

140 Posts

Posted - 2010-09-12 : 16:01:00
ah, I needed a begin and end statement :-P
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-16 : 13:06:35
you can simply do

insert into #crazy
select cast(number as varchar) + CAST(getdate() as varchar)
from master..spt_values
where type='p'
and number between 1 and 5

to avoid the loop

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-16 : 13:08:14
also see what happens when you dont specify length for character data

http://visakhm.blogspot.com/2010/02/importance-of-specifying-length-in.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-16 : 14:11:46
And why even bother with a temp table?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx





Go to Top of Page
   

- Advertisement -