| Author |
Topic |
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 03:04:24
|
| I made a stored procedure that update a counter, but it seems to be updated twice. Wha should I do to avoid that?Thank you very much. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-27 : 03:09:13
|
| Hard to tell without seeing the code.Do you suggest we should take an estimate or an educated guess?Peter LarssonHelsingborg, Sweden |
 |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 03:35:39
|
| My apology, well I’m using SQL server 2005, and it seems is working fine, but when I call that procedure it runs twice, not just one.declare @Contador bit, @thread_id int, @vizuais int--I'm setting these values, but I got them from the parameterset @Contador = 1set @thread_id = 29if (@Contador = 1) Begin Select @vizuais = vizuais from threads where thread_id = @thread_id set @vizuais = @vizuais + 1 Update threads set vizuais = @vizuais where thread_id = @thread_id EndSelect @vizuais as 'vizuais'Thank you Peso for the quick reply. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-27 : 07:12:14
|
| set @Contador = 1set @thread_id = 29Update threads set vizuais = vizuais + 1 where thread_id = @thread_id and @Contador = 1------------------------------------------------------------------Do you have a TRIGGER?Peter LarssonHelsingborg, Sweden |
 |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 13:31:41
|
| no I don't have one TRIGGER. To be honest I don't know what is for. I'll check it out. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-27 : 13:33:28
|
| Check your code that calls the procedure.Peter LarssonHelsingborg, Sweden |
 |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 13:44:16
|
| The code is fine, just call one time the procedure. I can see in Debug mode in MVS. |
 |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 13:59:36
|
It's the Update that is executing twice, when I call the procedure.I'll increase @vizuais out of SQL Server. I'll a consult before and record the new value straight on foruns table, if there is no alternative.Thank you very much anyway. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-03-27 : 15:37:14
|
quote: Originally posted by rsegecin Update threads set vizuais = @vizuais where thread_id = @thread_id
Is thread_id unique? Perhaps it is executing twice because there are two with that same id?? |
 |
|
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-27 : 23:03:19
|
| yes it is unique. I found some threads saying that if you call a procedure, which have update statement, from another application, it will be executed twice. Look what nr says at 20:34:44. [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78491#285157[/url]Thank you very much. |
 |
|
|
|