Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transact SQL and synchrone execution 1

Status
Not open for further replies.

gmanouvrier

Programmer
Apr 2, 2004
5
FR
Hi,
I have a stored pocédure which open a cursor and incremente a variable according to certain criteria. Then, I would have liked that my stored procedure turns over the value. However, I noticed that the execution of the sotckée procedure were made way asynchrone.Aussi, no value is not turned over because the stored procedure leaves before providing me the result. How could I make synchronous the éxecution of my procedure?
For example this procédure return 0 instead of returning 500 :
CREATE PROCEDURE GetTransfertCount
@id_t int, @@transferts int output
AS
set @@transferts=500

DECLARE story CURSOR FOR
SELECT * FROM history_ticket WHERE id_ticket=@id_t

declare @cpt int

OPEN story

FETCH NEXT FROM story
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM story
--my real code with real incrementation
END

CLOSE story
DEALLOCATE story


return @@transferts
 
You are not populating @@Transferts after the initial setting.

This does not sound like a task which needs a cursor. Why are you using one? Cursors are extremely inefficient and are to be avoided at all costs.
 
Hi SQLSister, thanks for your advice about cursors.
i know i don't need cursor for the sample i send, but it was only a sample.
In fact, this is my problem :
I have some users tranfsering a "job" and i have to track the real transferts number.
For exemple :

user A creation 2004/01/01 (level 1)
user A Modification 2004/01/02
user A Modification 2004/01/03
user A Modification 2004/01/04
User B Modification 2004/01/05 (level 2)
user A Modification 2004/01/06 (level 3)
USER C Modification 2004/01/07 (level 4)
user A Modification 2004/01/08 (level 5)
user A Modification 2004/01/09

In this real case there are 4 transferts (level 1 to 2) (level 2 to 3) (3 to 4) and (4 to 5)
i should want to retreive this by using a simple query but i think i should better delegate this task
to my asp pages :)
therefore, the discussion is open... :)
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top