Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
hi all,


i am trying to create a table valued  <u>SPLIT </u>function that uses CTE's recursive functionality to get records from the user parameters. the function is returning the values for parameter as expected if the parameter value (accounts) count is less than 100 and if the number of user parameter (accounts) are more than 100 then the function is failing and returning an error message: <b>maximum recursion 100 reached.</b>

If anyone can give a solution or a better method to implement the same logic is appreciated.
Posted

1 solution

Use:
SQL
;WITH CTE AS
(
    --select
)
SELECT 
FROM CTE
OPTION (MAXRECURSION 0)  --here!


See: WITH common_table_expression (Transact-SQL)[^]
 
Share this answer
 
Comments
Member 11052008 28-Apr-15 6:50am    
Thanks for the reply.

my query follows like below:

;with CTE_Account As (

select left(@temp_Accounts,charindex('.',@temp_Accounts)-1) as Account_Id_Level,

stuff(@temp_Accounts,1,charindex('.',@temp_Accounts),'') as rest_str,

substring(@temp_Accounts,charindex(',',@temp_Accounts)+1,7000) as rest_Accounts

Union All

select left(rest_Accounts,charindex('.',rest_Accounts)-1) as Account_Id_Level,

stuff(rest_Accounts,1,charindex('.',rest_Accounts),'') as rest_str,

case when charindex(',',rest_Accounts) <> 0 then substring(rest_Accounts,charindex(',',rest_Accounts)+1,7000)

else '' END as rest_Accounts

from CTE_Account where rest_Accounts <> ''



),


Cte_Source_Account_Codes
as
(

Select distinct Convert(int,Account_ID_LEVEL) AS Source_Account_id,Ods_Instance_ID as Source_Database_id, Level as Account_Level_Number
from (

select *,cast(substring(rest_str,1,charindex('.',rest_str)-1) as int) as Ods_Instance_Id,

cast(substring(rest_str,charindex('.',rest_str)+1,1) as int) as level

from (select Account_Id_Level,rest_str,rest_Accounts from CTE_Account) b
) a
)


If you have any idea where to give the hint: option (maxrecursion 1000). While browsing on this issue,i got to know that no table hint is allowed in recursive cte in UDF.

Please let me know if you have any idea on this or some other solution related to this issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900