Delete top n according to the variable

declare @num int;
select @num=count(*) from budget where fk_project_id=62;

declare @topstr nVARCHAR(256);
set @topstr='select top'+str(@num) +' * from budget';

execute sp_executesql @topstr ;

 

declare @num int;
select @num=count(*) from budget where fk_project_id=62;

declare @topstr nVARCHAR(256);
set @topstr='select top'+str(@num) +' * from budget'; 

execute sp_executesql @topstr ;

 

 

你可能感兴趣的:(variable)