Yes i tink but i was importing 3250 products directli into DB and i know how to directly solve this problem but i wuld like to have code that solving this problem from php. Does anyone knows how to modify this for php? ALTER FUNCTION [dbo].[GetOJChildren] ( -- Add the parameters for the function here @OJID int ) RETURNS @Table TABLE ( OJID int, Naziv varchar(110), ParentID int, HasChildren int ) AS BEGIN insert into @Table select OJID, isnull(Sifra + ' ', '') + Naziv, ParentID, (select count(*) from [dbo].[GetOJChildren](OJID)) from OrganizacijskeJedinice where isnull(ParentID, 0) = isnull(@OJID, 0) and Aktivno = 1 RETURN END