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
 Old Forums
 CLOSED - General SQL Server
 cursor

Author  Topic 

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-18 : 09:14:22
hello,
i have created one cursor for exec n times the sqme stored procedure but he don't work correctly.

I print correct the fifty value of @idRepTag but call only two times a stored procedure, why???



declare @IdRepTag int, @TagError int, @EvError int, @IdRepEvent int


--with this cursor retrive a IdTag from table RepTagConfig and pass them to mycursor
declare mycursor cursor for
select ScDon10.dbo.RepTagConfig.IdRepTag
from ScDon10.dbo.RepTagConfig inner join ScDon10.dbo.RepTableConfig
on ScDon10.dbo.RepTagConfig.IdRepTable = ScDon10.dbo.RepTableConfig.IdRepTable
where (ScDon10.dbo.RepTableConfig.TableName = @InvolvedTable)



open mycursor


FETCH NEXT FROM mycursor INTO @IdRepTag
WHILE @@FETCH_STATUS <>-1
BEGIN
print 'tag retirved from doProcessData '
print @IdRepTag
--retrive value from RepTagConfig, check ConditionInsert - ConditionValue
-- and insert or update data into TagTableValue
exec doSetTags @InvolvedTable, @IdRegister,@OperationType, @HeatID, @HeatNumber,@OrderNumber, @IdRepTag, @TagError output

if (@TagError <>0)
begin
set @DoError = @TagError+@TagError
end

FETCH NEXT FROM mycursor INTO @IdRepTag
end

CLOSE mycursor
DEALLOCATE mycursor


this is the result

chiamo la stored procedure
doProcessData
tag retirved from doProcessData
308
tag retirved from doProcessData
309
tag retirved from doProcessData
310
tag retirved from doProcessData
311
tag retirved from doProcessData
312
tag retirved from doProcessData
313
tag retirved from doProcessData
314
tag retirved from doProcessData
315
tag retirved from doProcessData
316
tag retirved from doProcessData
317
tag retirved from doProcessData
318
tag retirved from doProcessData
319
tag retirved from doProcessData
320
tag retirved from doProcessData
321
tag retirved from doProcessData
322
select DISTINCT @lsres = ScDon10.dbo.cprConfiguration.[Name], @lsval = involved.HeatsCounter FROM ScDon10.dbo.RepTagConfig INNER JOIN ScDon10.dbo.cprConfiguration ON ScDon10.dbo.RepTagConfig.IdTag = ScDon10.dbo.cprConfiguration.IdTag INNER JOIN ScDon10.dbo.crpTagType ON ScDon10.dbo.cprConfiguration.IdTagType = ScDon10.dbo.crpTagType.IdTagType cross Join eVisionDonasid.dbo.CCEquipments as involved where (ScDon10.dbo.RepTagConfig.IdRepTag=322 ) and (involved.CCEquipmentID =5)
Sep 18 2006 3:08PM
tgpCcNUMTund1Counter
1
direct tag
tag retirved from doProcessData
323
tag retirved from doProcessData
324
tag retirved from doProcessData
325
tag retirved from doProcessData
326
tag retirved from doProcessData
327
tag retirved from doProcessData
328
tag retirved from doProcessData
329
tag retirved from doProcessData
330
tag retirved from doProcessData
331
tag retirved from doProcessData
332
tag retirved from doProcessData
333
tag retirved from doProcessData
334
tag retirved from doProcessData
335
tag retirved from doProcessData
336
tag retirved from doProcessData
337
tag retirved from doProcessData
338
tag retirved from doProcessData
339
tag retirved from doProcessData
340
tag retirved from doProcessData
341
tag retirved from doProcessData
342
tag retirved from doProcessData
343
tag retirved from doProcessData
344
tag retirved from doProcessData
345
tag retirved from doProcessData
346
tag retirved from doProcessData
347
tag retirved from doProcessData
348
tag retirved from doProcessData
349
select DISTINCT @lsres = ScDon10.dbo.cprConfiguration.[Name], @lsval = involved.TimeCounter FROM ScDon10.dbo.RepTagConfig INNER JOIN ScDon10.dbo.cprConfiguration ON ScDon10.dbo.RepTagConfig.IdTag = ScDon10.dbo.cprConfiguration.IdTag INNER JOIN ScDon10.dbo.crpTagType ON ScDon10.dbo.cprConfiguration.IdTagType = ScDon10.dbo.crpTagType.IdTagType cross Join eVisionDonasid.dbo.CCEquipments as involved where (ScDon10.dbo.RepTagConfig.IdRepTag=349 ) and (involved.CCEquipmentID =5)
Sep 18 2006 3:08PM
tgpCcNUMTund1HeatCounter
0.00
direct tag
tag retirved from doProcessData
350
tag retirved from doProcessData
351
tag retirved from doProcessData
352
tag retirved from doProcessData
353
tag retirved from doProcessData
354
tag retirved from doProcessData
355
tag retirved from doProcessData
356
tag retirved from doProcessData
357
tag retirved from doProcessData
358
tag retirved from doProcessData
359
tag retirved from doProcessData
360
tag retirved from doProcessData
361


but it must be

tag retirved from doProcessData
359
exec stored procedure
tag retirved from doProcessData
360
exec stored procedure
tag retirved from doProcessData
361
exec stored procedure
.......

where is the error???

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-18 : 09:23:00
What does doSetTag look like?

Also, there is no need to check for @TagError <> 0. Any value plus zero is same value.
And the code for addition is wrong. @DoError is updated for every run to twice the value of @TagError!

if (@TagError <>0)
begin
set @DoError = @TagError+@TagError
end


set @DoError =@DoError + @TagError

or

IF @TagError <> 0
set @DoError =@DoError + 1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-18 : 09:27:59
doSetTag retrive value from table where idRepTag is equal to @IdRepTag
and if i exec select with the all single value he work correctly
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-18 : 09:32:45
The only thing, right now, that I can think of, is that exec doSetTags manipulates the ScDon10.dbo.RepTagConfig table or the ScDon10.dbo.RepTableConfig table.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-18 : 09:33:46
The stored procedure IS called every time. But somehow, the code in doSetTags only prints twice.
To make sure this is the case, add
print 'doSetTags param @IdRepTag' + CONVERT(VARCHAR, @IdRepTag)
as the first line the the stored procedure


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-18 : 14:10:05
No answer, no feedback.
I wonder if I hit a homerun with my answers?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

casati74
Posting Yak Master

109 Posts

Posted - 2006-09-19 : 08:52:45
YES thank's
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-19 : 09:49:56
Wouldn't that be

quote:

Sì, grazie





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
   

- Advertisement -