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.
| Author |
Topic |
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-19 : 20:05:54
|
| Hello all,i know this is prob the easy example i could find but could anyone help me to remove this cursordbo.ENTITY_ITEM PK = (ENTITYITEMID,MAJORBUILDNO,MINORBUILDNO)dbo.ENTITYID PK = (ENTITYID,MAJORBUILDNO,MINORBUILDNO)DECLARE entCursor CURSOR FAST_FORWARDFOR SELECT EntityId FROM dbo.ENTITYWHERE EntityTypeId = 0 AND MajorBuildNo = 0 AND MinorBuildNo = 0 OPEN entCursorFETCH NEXT FROM entCursor INTO @EntityIDWHILE @@fetch_status = 0BEGINUPDATE dbo.ENTITY_ITEM SET SizeUpdated = 1WHERE TypeId = @EntityID AND MajorBuildNo = 0 AND MinorBuildNo = 0UPDATE dbo.ENTITY SET SizeUpdated = 1WHERE EntityId = @EntityID AND MajorBuildNo = 0 AND MinorBuildNo = 0UPDATE dbo.ENTITY SET NewSizeOfEntity = SizeOfEntityWHERE EntityId = @EntityID AND MajorBuildNo = 0 AND MinorBuildNo = 0FETCH NEXT FROM entCursor INTO @EntityIDENDCLOSE entCursorDEALLOCATE entCursorthanks |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-12-19 : 20:20:07
|
| Could be done as a single update but simpler as two.update ENTITY_ITEMSET SizeUpdated = 1where TypeId in (SELECT EntityId FROM dbo.ENTITY WHERE EntityTypeId = 0 AND MajorBuildNo = 0 AND MinorBuildNo = 0)and MajorBuildNo = 0 AND MinorBuildNo = 0update ENTITYSET SizeUpdated = 1 ,NewSizeOfEntity = SizeOfEntityWHERE EntityTypeId = 0 AND MajorBuildNo = 0 AND MinorBuildNo = 0==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-19 : 20:25:51
|
| thanks nr your a champ :) |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-19 : 20:35:49
|
| sorry nr but wouldn't the last update look like thisupdate ENTITYSET SizeUpdated = 1 ,NewSizeOfEntity = SizeOfEntityWHERE EntityId in (SELECT EntityId FROM dbo.ENTITY WHERE EntityTypeId = 0 AND MajorBuildNo = 0 AND MinorBuildNo = 0)AND MajorBuildNo = 0 AND MinorBuildNo = 0? like the first update statment? |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-19 : 20:43:31
|
| Also got another harder one that i cant get outDECLARE entDecCursor CURSOR FAST_FORWARDFOR SELECT EntityId, DeclarationOrder FROM dbo.ENTITY WHERE MajorBuildNo = 0 AND MinorBuildNo = 0OPEN entDecCursorDECLARE @EntityId int, @ParentDeclarationOrder intFETCH NEXT FROM entDecCursor INTO @entityID, @ParentDeclarationOrderWHILE @@fetch_status = 0BEGIN IF (@CurrDeclarationOrder < @ParentDeclarationOrder) BEGINUPDATE dbo.ENTITY SET DeclarationOrder = @ParentDeclarationOrder + 1WHERE EntityId in ( SELECT ChildId FROM ENTITY_DEPENDENCYWHERE ParentId = @EntityId AND MajorBuildNo = 0 AND MinorBuildNo = 0)AND MajorBuildNo = 0 AND MinorBuildNo = 0END FETCH NEXT FROM entDecCursor INTO @entityID, @ParentDeclarationOrderENDCLOSE entDecCursorDEALLOCATE entDecCursor |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-12-19 : 21:10:23
|
quote: Originally posted by Ex sorry nr but wouldn't the last update look like thisupdate ENTITYSET SizeUpdated = 1 ,NewSizeOfEntity = SizeOfEntityWHERE EntityId in (SELECT EntityId FROM dbo.ENTITY WHERE EntityTypeId = 0 AND MajorBuildNo = 0 AND MinorBuildNo = 0)AND MajorBuildNo = 0 AND MinorBuildNo = 0? like the first update statment?
pk is ENTITYID,MAJORBUILDNO,MINORBUILDNOso MajorBuildNo = 0 AND MinorBuildNo = 0 will give unique ENTITYID's so there's no need fr the in clause.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|