Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accumulating in a local variable
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00662107
Message ID:
00662108
Views:
18
The fetch command should be at the end of WHILE loop, otherwise you're skipping the first record.
		SET @txt = @txt + @txtaux
		FETCH NEXT FROM cur_text INTO @txtaux
>I need to accumulate in a local variable a valstring value.
>But, for some reason, this not working, the code is:
>
>USE Osiris
>GO
>
>DECLARE @txt VARCHAR(1000)
>DECLARE @txtaux VARCHAR(120)
>
>SET @txt = ''
>SET @txtaux = ''
>
>DECLARE cur_text CURSOR FOR
>   SELECT texto FROM Universe.dbo.textOdi
>             WHERE Universe.dbo.textOdi.certif = 'PM115451'
>	OPEN cur_text
>	FETCH NEXT FROM cur_text INTO @txtaux
>	WHILE @@FETCH_STATUS = 0
>	BEGIN
>		FETCH NEXT FROM cur_text INTO @txtaux
>		SET @txt = @txt + @txtaux
>	END
>	CLOSE cur_text
>	DEALLOCATE cur_text
>
>PRINT @txt
>
>
>Why the @txt local variable doesn't have any accumulated value, if this value this being assigned with the SET commando ?
>
>Thanks.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform