Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:34:46+00:00 2026-06-15T05:34:46+00:00

I have a table called dbo.Node: NodeID int ParentNodeID int Title The following functions

  • 0

I have a table called dbo.Node:

NodeID      int
ParentNodeID    int
Title

The following functions shows the hierarchy

<cffunction name="getNodePath" returnType="string">
    <cfargument name="NodeID" required="false" default="">

    <cfset var qryNode = "">

    <cfif NOT isNumeric(arguments.nodeID)>
        <cfreturn "">
    </cfif>

    <cfquery name="qryNode" cachedWithin="#CreateTimeSpan(0,0,1,0)#">
        SELECT  ParentNodeID, Title
        FROM    dbo.Node WITH (NOLOCK)
        WHERE   NodeID = <cfqueryparam CFSQLType="CF_SQL_INTEGER" value="#arguments.NodeID#">
    </cfquery>      

    <cfreturn getNodePath(qryNode.ParentNodeID) & qryNode.Title & " &raquo; ">
</cffunction>

This code uses cacheWithin because it is known that many of the same parent path will be called. On average this gets called about 20 times from the original page. Overall it gets called 100s of times because of the recursive nature of the query. Furthermore this function returns a string. This means the formatting is in the model not the view.

Is there a way to replace this with a CTE?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:34:47+00:00Added an answer on June 15, 2026 at 5:34 am

    Version with CTE

    <cfset var qryNode = "">
    <cfset var lstPath = "">
    
    <cfif NOT isNumeric(arguments.nodeID)>
        <cfreturn QueryNew("Empty")>
    </cfif>
    
    <cfquery name="qryNode">
        WITH Family AS ( 
    
            SELECT  N.NodeID, ISNULL(N.ParentNodeID, '') AS ParentNodeID, Slug, N.Title, N.Kind, 0 AS Depth, N.CreateDate
            FROM    dbo.vwNode N WITH (NOLOCK)
            WHERE   NodeID = TRY_CONVERT(int, <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.NodeID#">)
    
            UNION ALL 
    
            SELECT  N2.NodeID, ISNULL(N2.ParentNodeID, '') AS ParentNodeID, N2.Slug,  N2.Title, N2.Kind, Depth + 1, N2.CreateDate
            FROM    dbo.vwNode N2 WITH (NOLOCK)
    
            INNER JOIN  Family 
            ON      Family.ParentNodeID = N2.NodeID
            WHERE   PrimaryRecord = 0 
            ) 
    
    
        SELECT  NodeID, ParentNodeID, Slug, Title, Kind, Depth, CreateDate
        FROM    Family
        ORDER BY Depth DESC
    </cfquery>      
    
    <cfreturn qryNode>
    

    The With statement replaces the recursive call. This function is now called only about 20 times. There is no need to cache the results because they will not get reused. The function now returns a query. The formatting is now on the view where it belongs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called 'survey_product' with the following structure: id int(11) order_id int(11)
So here's the setup. I have two tables: CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)
i have table called as Support, which have a field named Name and contains
I have a table dbo.comp has id and name as columns. dbo.comp Name id
I have a table in SQL Server 2000 Standard Edition called dbo.T668 (don't blame
I have a table in my SQL Server 2008 database called dbo.app_additional_info which contains
I have a table called Phone_Details and the data looks like: Name DeviceType InvoiceDate
I have a table called PurchaseOrderDetail. TABLE PurchaseOrderDetail PurchaseOrderDetail int, Comments nvarchar(500) In the
I have a table called dbo.Tbl_ActivityInformations and the data look like Activityid activitymaxcount Activityusedcount
I have a table dbo.Trans which contains an id called bd_id (varchar) and transfer_date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.