Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Accumulating in a local variable
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00662107
Message ID:
00662108
Vues:
19
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform