| Author |
Topic |
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-23 : 19:53:37
|
| Hey guys i got a problem converting this cursor :) into set based. And i was doing so well with all the others, just got to get my head around this oneIts the if else statment that is buggaring me upDECLARE iterDeleted CURSOR FAST_FORWARDFORSELECT DIMENSIONNO, DEFINEID FROM deleted where MAJORBUILDNO = 0 and MINORBUILDNO = 0OPEN iterDeletedDECLARE @DIMENSIONNO int , @DEFINEID int, @ENTITYITEMID intFETCH NEXT FROM iterDeleted INTO @DIMENSIONNO, @DEFINEID, @ENTITYITEMIDWHILE @@fetch_status = 0BEGIN DECLARE @Evaluated intSELECT @Evaluated = Evaluated FROM dbo.DEFINEWHERE defineid = @DEFINEID AND MajorBuildNo = 0 AND MinorBuildNo = 0 IF (@DIMENSIONNO = 0) BEGINUPDATE ENTITY_ITEM_VIEWSET TotalDimElements = 1WHERE EntityItemID = @ENTITYITEMID AND MajorBuildNo = 0 AND MinorBuildNo = 0ENDELSE IF (@Evaluated > 0) BEGINUPDATE ENTITY_ITEM_VIEWSET TotalDimElements = TotalDimElements / @EvaluatedWHERE EntityItemID = @ENTITYITEMID AND MajorBuildNo = 0 AND MinorBuildNo = 0END FETCH NEXT FROM iterDeleted INTO @DIMENSIONNO, @DEFINEID, @ENTITYITEMIDENDCLOSE iterDeletedDEALLOCATE iterDeletedany help would be appricated |
|
|
clarkbaker1964
Constraint Violating Yak Guru
428 Posts |
Posted - 2004-12-23 : 20:29:17
|
Its possible your Select assignment for @Evaluated returned Null |
 |
|
|
clarkbaker1964
Constraint Violating Yak Guru
428 Posts |
Posted - 2004-12-23 : 20:30:53
|
See if you can convert these to using #Temp tables with While loops and get away from cursors. It looks like you could use Insert into #Temp and loop through the recordsets with While. |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2004-12-24 : 02:06:53
|
| Is this within a trigger? If so, what is the base table?HTH=================================================================Sometimes I wonder whether the world is being run by smart people who are putting us on or by imbeciles who really mean it. -Mark Twain, author and humorist (1835-1910) |
 |
|
|
hgorijal
Constraint Violating Yak Guru
277 Posts |
Posted - 2004-12-24 : 02:31:57
|
| You are missing ENTITYITEMID in your cursor definition ???????Hemanth GorijalaExchange a Dollar, we still have ONE each._______Exchange an Idea, we both have TWO each. |
 |
|
|
hgorijal
Constraint Violating Yak Guru
277 Posts |
Posted - 2004-12-24 : 02:37:59
|
replace all the code with these two update statement.. Does this work...?UPDATE A SET TotalDimElements = 1 FROM ENTITY_ITEM_VIEW A, deleted B WHERE A.EntityItemID = B.ENTITYITEMID AND A.MajorBuildNo = 0 AND A.MinorBuildNo = 0 AND B.DIMENSIONNO = 0UPDATE A SET TotalDimElements = TotalDimElements / C.Evaluated FROM ENTITY_ITEM_VIEW A, deleted B, dbo.DEFINE C WHERE A.EntityItemID = B.ENTITYITEMID AND A.MajorBuildNo = 0 AND A.MinorBuildNo = 0 AND B.DIMENSIONNO <> 0 AND C.defineid = B.DEFINEID AND C.MajorBuildNo = 0 AND C.MinorBuildNo = 0 Hemanth GorijalaExchange a Dollar, we still have ONE each._______Exchange an Idea, we both have TWO each. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-12-27 : 14:33:31
|
quote: Originally posted by clarkbaker1964 See if you can convert these to using #Temp tables with While loops and get away from cursors. It looks like you could use Insert into #Temp and loop through the recordsets with While.
Using a WHILE loop is only slightly better than a cursor. Both require looping. Neither is set-based.Tara |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-12-27 : 15:15:43
|
I can name that update in 1 statement :)UPDATE eSET TotalDimElements = CASE WHEN d.DIMENSIONNO = 0 THEN 1 ELSE d.TotalDimElements / d.Evaluated ENDFROM Deleted d, ENTITY_ITEM_VIEW eWHERE e.ENTITYITEMID = d.ENTITYITEMID AND e.MajorBuildNo = 0 AND e.MinorBuildNo = 0 |
 |
|
|
|