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
 what is going on??

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 Larsson
Helsingborg, Sweden
Go to Top of Page

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 parameter
set @Contador = 1
set @thread_id = 29

if (@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
End

Select @vizuais as 'vizuais'

Thank you Peso for the quick reply.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-27 : 07:12:14
set @Contador = 1
set @thread_id = 29

Update threads set vizuais = vizuais + 1 where thread_id = @thread_id and @Contador = 1

------------------------------------------------------------------
Do you have a TRIGGER?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

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.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-27 : 13:33:28
Check your code that calls the procedure.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-27 : 14:01:23
Well assuming there are no miracles...something is going on...go into Enterprise Manager and script the table and choose the option to script triggers



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

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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??
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -