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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 IF ELSE IF in Cursor

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-03-19 : 23:06:31
Matt writes "Can you use an IF ELSE IF in a cursor. I need to assign variables in to be evaluated, then based on the evaluation apply a formula on the other variables. Something like this:

declare @selLineItemId float
declare @Lengthunits varchar(50)
declare @Widthunits varchar(50)
declare @Length varchar(25)
declare @Width varchar(25)
declare @Area varchar(25)

DECLARE c1 CURSOR FOR
Select a.idx, a.configuredLengthX, a.configuredLengthUnitsOfMeasurX, a.configuredWidthX, a.configuredWidthUnitsOfMeasureX
from selLineItemT a, poHub b
where a.idx = b.SelLineItemID

OPEN C1

FETCH NEXT FROM c1
into @selLineItemId, @Length, @Lengthunits, @Width, @Widthunits

WHILE @@FETCH_STATUS = 0
BEGIN

IF (@Lengthunits = 'yards')
@Length * 36
@Length = @Area
@Area = 0
(@Lengthunits) = 'feet'

Else IF (@Lengthunits = 'feet')
BEGIN
@Area = @Length * 12
@Length = @Area
@Area = 0
END
@Area = (@Length*@Width)/1000
print @Area

FETCH NEXT FROM c1
into @selLineItemId, @Length, @Lengthunits, @Width, @Widthunits

END
CLOSE c1
DEALLOCATE c1"
   

- Advertisement -