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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:44:47+00:00 2026-06-05T06:44:47+00:00

Hi I am currently creating My SP that insert and detete records based on

  • 0

Hi I am currently creating My SP that insert and detete records based on the result given by my select statement.

This is my sample Code:

DECLARE @PickListBatchName varchar(200),
@PartNumber varchar(50),
@QTY int;

SET @PickListBatchName='TEST1';
SET @PartNumber='PN1';
SET @QTY=1;


      --STEP 1 Add Result to TempTable
      With SN as
      (
        SELECT TOP (@QTY) 
           pb.PickListBatchId
           ,pt.PickListTRANId
           ,pt.SerialNumber
           ,pt.Createdby
           ,pt.CreatedDT
FROM PickListTRAN pt 
            LEFT JOIN PickListBatchDetail pdb ON pdb.PickListBatchDetailId=pt.PickListBatchDetailId
            LEFT JOIN PickListBatch pb ON pdb.PickListBatchId=pb.PickListBatchId
where  pb.PickListBatchName=@PickListBatchName AND pdb.PartNumber=@PartNumber
      )


    --STEP 2: INSERT SN TO PicklistTranCancel
    INSERT INTO PickListTRANCancel
   (
   PickListBatchId
   ,SerialNumber
   ,CreatedBy
   ,CreatedDT
   ) 
   (SELECT  
           PickListBatchId,
           SerialNumber,
           Createdby,
           CreatedDT
    FROM SN);

    --STEP 3: DELETE Records on PicklistTran

    DELETE FROM PicklistTran where picklistTranId IN (SELECT PickListTRANId FROM SN)

result:

(1 row(s) affected)
Msg 208, Level 16, State 1, Line 49
Invalid object name 'SN'.  --error on delete statement

On Step 3, the delete statement cannot read SN table. maybe i’m missing something on that part.

Thanks in Regards

  • 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-05T06:44:49+00:00Added an answer on June 5, 2026 at 6:44 am

    Thanks @benni_mac_b and @praveen this is what i tried. I just use to create TempTable instead of using WITH.

    DECLARE @PickListBatchName varchar(200),
    @PartNumber varchar(50),
    @QTY int;
    
    SET @PickListBatchName='TEST1';
    SET @PartNumber='PN1';
    SET @QTY=1;
    
    Declare @MyTable table 
    (
         PickListBatchId int,
         PickListTRANId int,
        SerialNumber varchar(50),
        Createdby varchar(50),
        CreatedDT datetime
    );
    
    
     --STEP 1: insert to temptable 
     INSERT INTO @MyTable
                        (
               PickListBatchId,
               PickListTRANId,
               SerialNumber,
               Createdby,
               CreatedDT
                        )
    SELECT TOP (@QTY) 
               pb.PickListBatchId
               ,pt.PickListTRANId
               ,pt.SerialNumber
               ,pt.Createdby
               ,pt.CreatedDT
    FROM PickListTRAN pt 
                LEFT JOIN PickListBatchDetail pdb ON pdb.PickListBatchDetailId=pt.PickListBatchDetailId
                LEFT JOIN PickListBatch pb ON pdb.PickListBatchId=pb.PickListBatchId
    where  pb.PickListBatchName=@PickListBatchName AND pdb.PartNumber=@PartNumber
    
    
        --STEP 2: INSERT SN TO PicklistTranCancel
        INSERT INTO PickListTRANCancel
       (
       PickListBatchId
       ,SerialNumber
       ,CreatedBy
       ,CreatedDT
       ) 
       SELECT  
       PickListBatchId,
       SerialNumber,
       Createdby,
       CreatedDT
       FROM @MyTable
    
       --STEP 3: DELETE
       DELETE FROM PicklistTran where picklistTranId IN (SELECT PickListTRANId FROM @MyTable)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently in the process of creating an application that records current location
I'm creating a Linked List program and I currently have this method to insert
I'm currently creating a small C# program that inserts data from files into a
I am currently creating a program that dynamically adds Image to a dockPanel every
I'm currently creating an MVC application that will likely to expand to include a
I am currently creating a service which connects to a DAL and that can
Here's something that has been bugging me... I am currently creating an application for
I currently use visual studio 2008 for creating projects that can run on windows.
I am currently in the middle of creating an app that uses a sql
I'm creating an app that creates and saves images. Currently I am saving them

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.