Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Must declare the variable
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Must declare the variable
Divers
Thread ID:
00942650
Message ID:
00942650
Vues:
58
Can someone tell me how to get around this issue?
The Exec does not see my declare @NewId!

Server: Msg 137, Level 15, State 1, Line 1
Must declare the variable '@NewId'.
if exists (select * from sysobjects where id = object_id('Ims_sy_GetNextPrevID') and sysstat & 0xf = 4)
	drop procedure Ims_sy_GetNextPrevID
go
Create Procedure Ims_sy_GetNextPrevID


@Table	varchar(50),
@ReqID	int

as

BEGIN 
	declare @NewId 	int,
		@SqlCmd varchar(300),
		@cReqID	varchar(10)

	set @cReqID = ltrim(rtrim(STR(@ReqID, 12, 0)))
	set @NewId = -1
	
	set @SqlCmd ='select top 1 @NewId=' + @Table+'id into #TempFL from '+@Table +' where '+@Table+'id > ' + @cReqID 

	exec (@SqlCmd)
	Print @NewId

	set @NewId = isnull(@NewId,0)

	if @NewId = 0
		begin
			select top 1 @NewId=repflid 
				from repfl 
				where repflid < @ReqID
				order by repflid desc
		end
	
	select @NewId
END

go

dbo.Ims_sy_GetNextPrevID 'Repfl',103
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform