How to declare Dynamic Variable names

Aug 21 2019 1:41 AM
Hi,
I need to how to declare dynamic variable names from table  in a stored procedure i am using like below .but it wont work can anyone help me out .
 
WHILE @i < 6 --- (select Count(*) from List_Of_SMSC_Gateways where IsDeleted=0 )
BEGIN
select @gwayName= Gateway_Name from (SELECT ROW_NUMBER() OVER (ORDER BY Gateway_Name Asc) AS Rno, Gateway_Name
from List_Of_SMSC_Gateways where IsDeleted=0 ) as x where x.Rno=@i
set @sql=@sql+' Declare @'+@gwayName+'_reseller_Count Numeric = 0 , @'+@gwayName+'_smcountry_count Numeric = 0;'
set @sql=@sql+' Declare @Smsc_'+@gwayName+'_Total_count Numeric=0;'
set @sql=@sql+' Declare @Resller_'+@gwayName+'_Total_count Numeric=0;'
set @sql=@sql+' Declare @Total_'+@gwayName+'_cnt Numeric=0;'
set @i=@i+1
END;
execute(@sql)
 
 
and need to use this variable across stored procedure 
 
thanks in advance 
 
 

Answers (2)