iam working on sql query
i have @Table_1,@Table_2 Variable
i fill @Table_1 then i need to fill @Table_2 depend on value in @Table_1
for eaxmple
@Table_1
(
ID bigint,
CategoryID bigint
CategoryType tinyint
)
@Table_2
(
QUantity float
TotalSales float
totalcost float
)
&& i have i table valued function (Fn_Table) that take the paremeter from @TAble_! to fill @Table2
like the following code
**************************
declare @Pks int
declare @Pk int
declare @CategoryID bigint
select @Pks=count(ID) from @Table_1
select @pK=1
WHILE(@Pks>0)
begin
select @CategoryID=CategoryID from @Table_1 where ID=pk
if(@categoryid<>-1)
insert into @table_2 select quantity,TotalSales ,totalcost from dbo.fn_table(@CategoryID)
select @pks=@pks-1
select @pk=@pk+1
end
********************************
the query take long time & i think this is because ot the loop
so could anybody help me to get the same result without using loop
[edit]Code blocks added - OriginalGriff[/edit]