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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:30:18+00:00 2026-06-11T02:30:18+00:00

Here is my SP: USE [x] GO /****** Object: StoredProcedure [dbo].[sp_CopyCompanyContent] Script Date: 09/10/2012

  • 0

Here is my SP:

   USE [x]
GO
/****** Object:  StoredProcedure [dbo].[sp_CopyCompanyContent]    Script Date: 09/10/2012 12:35:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[sp_CopyCompanyContent]
(
        @intCopyFromCompanyID Int,
        @intNewCompanyID Int
)

As

Begin
    /*
        RaisError If any of Odl/New Company ID's are 0
    */

    If (@intCopyFromCompanyID = 0 Or @intNewCompanyID = 0)
        Begin
            RaisError('New Company ID or Old Company ID can not be 0', 16, 1)
            Return
        End


    /*
        Create Temp Table For the Content Sections
    */

    If Object_ID('tempdb..#ContentSections') IS Not Null
        Begin 
            Drop Table dbo.#ContentSections
        End 

    /*
        Have to get all the existing data for the Old company we are copying from.
        Have to also add the Max(ContentSectionID) From ContentSection. Max(ContentSectionID) + 
        The Identity (Added further down due to laziness) will be our seed for the ContentID
    */

    Select      CS.ContentID,
                CS.SectionID,
                CS.MenuOrder,
                @intNewCompanyID NewCompanyID,
                CS.CompanyID OldCompanyID,
                CS.SubMenu,
                CS.Link,
                CS.HeaderMenu,
                CS.ParentContentID,
                CRS.*

    Into        dbo.#ContentSections

    From        dbo.Company COMP
    Join        dbo.ContentSection CS
    On          COMP.Company_id = CS.CompanyID  
    Join        dbo.Content CONT
    On          CONT.ContentID = CS.ContentID

    Cross Join  (
                    Select  MAx(ContentSectionID) MaxContentSectionID
                    From    dbo.ContentSection CONT
                ) crs

    Where       COMP.Company_id  = @intCopyFromCompanyID
    Order By    COMP.Company_id


    /*
        We now need to create a table for the existing content for the old company.
        Also have to create the seed. Same principle as above.
    */


    If Object_ID('tempdb..#Content') IS Not Null
        Begin 
            Drop Table dbo.#Content
        End 

    Select  CONT.*, 
            CRS.*

    Into    dbo.#Content

    From    dbo.Company COMP
    Join    dbo.ContentSection CS
    On      COMP.Company_id = CS.CompanyID  
    Join    dbo.Content CONT
    On      CONT.ContentID = CS.ContentID

    Cross Join  (
                    Select  MAx(ContentID) MaxContentID
                    From    dbo.Content CONT
                ) crs

    Where   COMP.Company_id  = @intCopyFromCompanyID
    Order By COMP.Company_id

    /*  
        Add Identity to each of the tables we have created above. The ID fields will add to 
        the Max of each table to mimic what the future seeds will be.
    */

exec('Alter table #ContentSections Add ID Int Identity(1,1)')
exec('Alter table #Content Add ID Int Identity(1,1)')

    /*
        Add content data from the temp table.
    */


    Insert  Into dbo.Content
    (
            Title,
            Content
    )   
    Select  Title,
            Content 
    From    dbo.#Content

    /*
        Have to the Content table up to the content sections table
        as this contains what ID has been add to the Content Table. 
    */


    Insert Into dbo.ContentSection
    (
            ContentID,
            SectionID,
            MenuOrder,
            CompanyID,
            SubMenu,
            Link,
            HeaderMenu,
            ParentContentID
    )

    Select  C.MaxContentID + C.ID,
            CS.SectionID,
            CS.MenuOrder,
            CS.NewCompanyID,
            CS.Submenu,
            CS.Link,
            CS.HEaderMEnu,
            CS.ParentContentID
    From    dbo.#Content C
    Join    dbo.#ContentSections CS
    On      C.ID = CS.ID

End

When I run it I get the following:

For example:

(41 row(s) affected)

(41 row(s) affected)

Msg 207, Level 16, State 3, Procedure sp_CopyCompanyContent, Line 122
Invalid column name ‘ID’.
Msg 207, Level 16, State 3, Procedure sp_CopyCompanyContent, Line 122
Invalid column name ‘ID’.
Msg 207, Level 16, State 3, Procedure sp_CopyCompanyContent, Line 122
Invalid column name ‘ID’.

(1 row(s) affected)

Can anyone see why it says invalid column ID? It should be joining and filling the content perfectly..

  • 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-11T02:30:20+00:00Added an answer on June 11, 2026 at 2:30 am

    Try replace code:

     Alter table #ContentSections Add ID Int Identity(1,1)
     Alter table #Content Add ID Int Identity(1,1)
    

    with

    exec('Alter table #ContentSections Add ID Int Identity(1,1)')
    exec('Alter table #Content Add ID Int Identity(1,1)')
    

    or add to your “select into” identity column as below:

    SELECT  ID=IDENTITY (int, 1, 1) ....
    INTO    #Table
    FROM    Table
    

    for example:

     Select         ID=IDENTITY (int, 1, 1),
                    CS.ContentID,
                    CS.SectionID,
                    CS.MenuOrder,
                    @intNewCompanyID NewCompanyID,
                    CS.CompanyID OldCompanyID,
                    CS.SubMenu,
                    CS.Link,
                    CS.HeaderMenu,
                    CS.ParentContentID,
                    CRS.*
    
        Into        dbo.#ContentSections
    
        From        dbo.Company COMP
        Join        dbo.ContentSection CS
        On          COMP.Company_id = CS.CompanyID  
        Join        dbo.Content CONT
        On          CONT.ContentID = CS.ContentID
    
        Cross Join  (
                        Select  MAx(ContentSectionID) MaxContentSectionID
                        From    dbo.ContentSection CONT
                    ) crs
    
        Where       COMP.Company_id  = @intCopyFromCompanyID
        Order By    COMP.Company_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a second Activity to use the DropboxAPI object (mApi here) and invoke
If I use a here document in a shell script that contains multiple backslashes
Go Here Use UP and DOWN keys When I press a key, the red
Does anyone here use phpmailer? I downloaded the files for phpmailer 5.2.1 (the newest
I don't understand what happens here : use PAR { file => 'foo.par', fallback
Here I use two images. when i click once on the Sort_down.png image then
I'm trying to create a web application project template for everyone to use here
hy, i need a little help here: i use SWFupload to upload images! in
Here's the use case: A user clicks on a link that opens a window
Has anyone here tried to use a custom animation with MBProgressHUD. There is a

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.