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 |
|
shifis
Posting Yak Master
157 Posts |
Posted - 2006-04-11 : 11:58:32
|
| Exist a funtion that I can use in a SP that do something like the for to next or Do while Loop do? |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-04-11 : 12:00:57
|
| Look up WHILE in Books Online.. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
shifis
Posting Yak Master
157 Posts |
Posted - 2006-04-11 : 17:38:03
|
| Im trying to do this, but i cant make it workdeclare @intNoTarjIni as floatdeclare @intNoTarjFin as floatdeclare @err as intset @intNoTarjIni = 123456789set @intNoTarjFin = 123456799while @intNoTarjIni < @intNoTarjFinbeginBEGIN TRAN insert tbTarjetas values(@intNoTarjIni, 'I') SELECT @err = @@error IF (@err <> 0) BEGIN ROLLBACK TRAN GOTO ERR_HANDLER BREAK END else COMMIT TRANendbeginERR_HANDLER: select 0 as resultend |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-04-12 : 05:23:37
|
| That will give you an infinite loop because @intNoTarjIni is always less than @intNoTarjFin. Try changing one of them somewhere in the loop - e.g. increment @intNoTarjIni...Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-04-12 : 05:32:01
|
By the way, since Brett mentioned set-based logic, you might want to be aware of this kind of technique. Just run it to see...  --datadeclare @tbTarjetas table (x float, c char(1))declare @intNoTarjIni as floatdeclare @intNoTarjFin as floatset @intNoTarjIni = 123456789set @intNoTarjFin = 123456799--calculationdeclare @numbers table (i int identity(0, 1), x bit)insert @numbers select top 1000 null from master.dbo.syscolumns a, master.dbo.syscolumns binsert @tbTarjetas select @intNoTarjIni + i, 'I' from @numbers where i < @intNoTarjFin - @intNoTarjIniselect * from @tbTarjetas Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|
|
|