Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,714 of 19,505    |
|    phdate to All    |
|    Number generator    |
|    11 Dec 09 14:49:20    |
      From: drscrypt@gmail.com              Over the last couple of days, I have tried lots of ways to generate       sequential numbers within a user defined function, including a stored       proc to compute the next number and a function to return it. (I need       this ability as part of a larger scientific package, and it needs to be       a function). I get errors similar to this:              "Only functions and extended stored procedures can be executed from       within a function."                            Here is the latest non-working code I have after many changes. In       essence, each time I call num_gen() function, I would like a new number       to be returned, and which can be used from other functions:                     -- create the table       create table num_gen_table (id int)       go       insert into num_gen_table values (1)       go                     -- sproc to move to next number       create proc update_num_gen_table as        update num_gen_table set id=id + 1       go                     -- function to return the next number       create function num_gen () returns int as       begin        declare @new_num int               exec update_num_gen_table        select @new_num = id from num_gen_table        return @new_num       end              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca