the best soultion is create a cursor and put cursor in stored procedure(SP) , finally call SP ------------------------------- declare @vdd bigint declare C1 cursor for Select distinct id from pdata open C1 drop table #temsales CREATE TABLE #temsales ( col1 bigint, col2 datetime, col3 bigint ) fetch next from c1 into @vdd while @@fetch_status=0 begin insert into #temsales select top 5 * from pdata where sales>0 and id =@vdd fetch next from c1 into @vdd end close c1 deallocate c1 select * from #temsales ;)
F
faizankhan
@faizankhan