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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:59:01+00:00 2026-06-15T08:59:01+00:00

SQL 2005 I have a table called tPieceTable whose layout is like the following:

  • 0

SQL 2005

I have a table called tPieceTable whose layout is like the following:

ID   BatchNo    PieceNo
-----------------------
1    abc        123
2    xyz        321

In tPieceTable, “ID” is an IDENTITY(1,1).

I also have another table (tLiveTable) which has the following layout.

ID   TimeStamp  LocationRef
---------------------------

What I am trying to do is create a stored procedure which will INSERT the ID from tPieceTable INTO tLiveTable WHERE the BatchNo is equal to @BatchNo AND the PieceNo is equal to @PieceNo (these are parameters to the stored procedure).

I have the following which appears to be working:

CREATE PROCEDURE spSetLocationChargeTable
  @BatchNo nvarchar(50),
  @PieceNo nvarchar(50)
AS
  INSERT INTO tLiveTable(PieceID)
  SELECT ID FROM tPieceTable
  WHERE tPieceTable.BatchNo = @BatchNo AND tPieceTable.PieceNo = @PieceNo
GO

Now, at the same time as the INSERT, I want to update the TimeStamp for the new record as GetDate(), and for LocationRef I want insert the output of the following query:

SELECT ID FROM tLocationRefs WHERE Equipment = 'CHARGE_TABLE'

For reference tLocationRefs looks like this:

ID   Equipment     Description
------------------------------
0    CHARGE_TABLE  Charger Machine Table

Where I am struggling is how combine all this into one INSERT. I have tried doing an insert followed by two UPDATEs, but I cannot reference the tPieceTable, e.g. with the following:

CREATE PROCEDURE spSetLocationChargeTable
  @BatchNo nvarchar(50),
  @PieceNo nvarchar(50)
AS
  INSERT INTO tLiveTable(PieceID)
  SELECT ID FROM tPieceTable
  WHERE tPieceTable.BatchNo = @BatchNo AND tPieceTable.PieceNo = @PieceNo

  UPDATE tLiveTable
  SET TimeStamp = GetDate()
  WHERE tPieceTable.BatchNo = @BatchNo AND tPieceTable.PieceNo = @PieceNo

  UPDATE tLiveTable
  SET LocationRef = (SELECT ID FROM tLocationRefs WHERE Equipment = 'CHARGE_TABLE')
  WHERE BatchNo = @BatchNo AND PieceNo = @PieceNo
GO

I get :-

“The multi-part identifier “tPieceTable.BatchNo” could not be found.”
“The multi-part identifier “tPieceTable.PieceNo” could not be found.”

Thanks to all for any assistance.

  • 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-15T08:59:02+00:00Added an answer on June 15, 2026 at 8:59 am
    INSERT  INTO tLiveTable
            (PieceID, TimeStamp, LocationRef)
    SELECT  ID 
    ,       getdate()
    ,       (
            SELECT  ID 
            FROM    tLocationRefs 
            WHERE   Equipment = 'CHARGE_TABLE'
            )
    FROM    tPieceTable  
    WHERE   tPieceTable.BatchNo = @BatchNo
            AND tPieceTable.PieceNo = @PieceNo
    
    • 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 'Audit' in SQL Server 2005 like this: Name |
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.
SQL 2005, 600,000,000 rows. I have a table called Location currently using the data
In a SQL SERVER 2005 database, please suppose we have a table called RUNNING_COLA_IS_AFRICA.
I have a sql server 2005 table called ZipCode, which has all the US
I have a sql table called UsersInAuthentication like ----------------------- | AuthUserId | UserId |
I have a column on an SQL Server 2005 table called BIO - the
I have a SQL Server 2005 table called Users: UserID | Date | Name
I have table in Ms SQL Server 2005 (2008) in following structure ID Name
I have a SQL Server 2005 table called 'Contracts': CREATE TABLE Contracts ( ContractNo

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.