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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case in Fetch..? 1

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

Why can't I use the CASE statement together with FETCH

/Kent J.

DECLARE @type char(3),@cnt varchar(3),@test varchar(3)

DECLARE type_cursor CURSOR FOR
SELECT cnt,Type=left(tti,3) FROM tti_test

OPEN type_cursor

FETCH NEXT FROM type_cursor
INTO @cnt,@type

WHILE @@FETCH_STATUS = 0
BEGIN

case
when @type='315' then @test=@type
when @type='316' then @test=@test
end
PRINT @Cnt + ' ' + @type + ' ' + @test

FETCH NEXT FROM type_cursor
INTO @cnt,@type
END

CLOSE type_cursor
DEALLOCATE type_cursor

 
You can't use CASE like that. Use IF:

Code:
IF @type = '315'
  SET @test = @type
ELSE
  SET @test = @test

BTW, the use of a cursor here seems unnecessary - try and avoid them if possible.

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top