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 6111449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:37:54+00:00 2026-05-23T14:37:54+00:00

With a MS SQL Stored Procedure I am getting the following error Invalid Column

  • 0

With a MS SQL Stored Procedure I am getting the following error “Invalid Column Name NavigationID”.

Can anyone let me know what I am doing incorrectly?

DECLARE @NavigationID INT
SET @NavigationID = 5 

CREATE TABLE #tmp (NavigationID int , ParentID int);
INSERT INTO #tmp SELECT NavigationID, ParentID FROM Nav;

    WITH Parent AS
    (
        SELECT NavigationID, ParentID FROM #tmp WHERE NavigationID = @NavigationID
        UNION ALL 
        SELECT t.NavigationID, t.ParentID FROM Parent
        INNER JOIN #tmp t ON t.NavigationID =  Parent.ParentID
    )

    SELECT NavigationID FROM ParentID
    WHERE NavigationID <> @NavigationID;
  • 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-05-23T14:37:54+00:00Added an answer on May 23, 2026 at 2:37 pm

    With the code you posted you get.

    Msg 208, Level 16, State 1, Line 10
    Invalid object name 'ParentID'.
    

    Change FROM ParentID to FROM Parent.

    You also need a column NavigationID in table Nav.

    Try this:

    declare @Nav table(NavigationID int, ParentID int)
    
    insert into @Nav
    select 1, null union all
    select  2, 1 union all
    select  3, 1 union all
    select   4, 3 union all
    select   5, 3 union all
    select 6, null union all
    select  7, 6
    
    declare @NavigationID int;
    set @NavigationID = 5;
    
    
    with Parent as
    (
      select NavigationID,
             ParentID
      from @Nav
      where NavigationID = @NavigationID
      union all
      select t.NavigationID, t.ParentID
      from Parent
        inner join @Nav t
          on t.NavigationID =  Parent.ParentID
    )
    select NavigationID
    from Parent
    where NavigationID <> @NavigationID;
    

    Result:

    NavigationID
    ------------
    3
    1
    

    Replace @Nav with whatever table you are using. @Nav is only here so that this code can be copied and tested.

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

Sidebar

Related Questions

I'm getting the error when accessing a Stored Procedure in SQL Server Server Error
I'm getting a SQL Server error on a stored procedure (although it appears to
In my stored procedure I am getting the following error 'price=ROUND(' CONVERT(VARCHAR, changeValue) +
I write the following stored procedure in sql server 2008 i am getting the
I am getting the following error message with SQL Server 2005 Msg 120, Level
I created a stored procedure in a sql express 2008 and I'm getting the
Okay so I'm writing a SQL Server 2008 Stored Procedure (maintenance script). In doing
When running a stored procedure, we're getting the error 297 The user does not
I'm still getting used to SQL, so before I get to using stored procedure,
I am getting following error ERROR:- Incorrect syntax near '+'. while executing following T-Sql

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.