CONSTRAINT [PK_tabChar] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
) ON [PRIMARY]
GO
insert into tabChar
select 'aaaaa'
union select 'bbbbb'
union select 'ccccc'
union select 'ddddd'
union select 'eeeee'
union select 'fffff'
union select 'gggggg'
union select 'hhhhhh'
go
Create proc pAA(@counts int)
as
begin
set nocount on
create table #temptable(id int identity(1,1),storename varchar(50))
declare @str varchar(1000)
set @str = 'insert into #temptable '+
'select top '+cast(@counts as varchar(10))+
' name from tabChar'
exec (@str)
select * from #temptable