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

  • Home
  • SEARCH
  • 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 6128001
In Process

The Archive Base Latest Questions

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

I have two tables +———————————+ | Table A | +———-+———–+—-+—–+ | Part No |

  • 0

I have two tables

+---------------------------------+
|             Table A             |
+----------+-----------+----+-----+
| Part No  | Serial No | PO |  DO |
+----------+-----------+----+-----+
| 1AB1009  | GR7764    | ST | OND |
| 1AB1009  | GR7765    | ST | OND |
+----------+-----------+----+-----+

+-----------+
|  Table B  |
+-----------+
| Serial No |
+-----------+
|   GR7764  |
|   GR7765  |
+-----------+

Table B have only one column with unique serial no’s, am matching the serial no in both tables and updating the values if there is a match…my query is running nice for this but I have a scenario like first I upload a csv file to Table B then I will match…but Table A may not have some serial no’s, so if there is no match it should prompt me to go the add page to add the records to Table A and then perform update query.

This is my query

update TableA 
   set Mat_No ='"+ Mat_No+"',WO_No='"+WO_No+"',Code = '"+Code+"',
       Desc = '"+Desc+"',Center='"+Center+"',Date='"+Date+"',Remarks='"+Remarks+"' 
 where SerialNo in(select A.SerialNo 
                     from Table A, Table B 
                    where B.SerialNo = A.SerialNo and A.Status = 'IN');

First I will upload a csv file to table B then I fill all the details like MatNo etc then update if the csv file is having the serial no which are not in Table A then it should prompt me with all the serial no’s no match in table A…. don’t know how to do this?? Please help me out…

  • 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-23T16:34:38+00:00Added an answer on May 23, 2026 at 4:34 pm

    Here are the steps you can do:

  2. Load the CSV files (using any of BCP, BULK INSERT, Import export wizard, SSIS packages) for loading tableB. This process is independent of updating tableA.
  3. Now for TableA create an update trigger that checks for all the SNOs present in B and NOT in A while updating it. See below DDLs and queries as example and accordingly modify:
  4. 
    
        create  table TABLEA (
         PartNo varchar(30),
         SNo varchar(30),
         PO varchar(10),
         DO varchar(30))
    
         insert into TABLEA 
         select '1AB1009', 'GR7764', 'ST', 'OND'
         union
        select '1AB1009','GR7765','ST','OND'
    
        create  table TABLEB ( 
         SNo varchar(30)
        )
         insert into TABLEB
         select 'GR7764'
         union
         select 'GR7765'
    
         select * from TABLEA
         select * from TABLEB
         GO
    
    

    Now create an instead of Update trigger on tableA to warn about SNOs missing in tableA when trying to insert from front end app

    
    
        CREATE TRIGGER missingSNOs ON TABLEA
        INSTEAD OF UPDATE
        AS  
    
            BEGIN
                if EXISTS (SELECT 1
                                FROM TABLEB B
                                LEFT OUTER JOIN
                                INSERTED I
                                ON B.SNO = I.SNO
                                WHERE I.SNO IS NULL
                                )
                begin
                         SELECT B.SNO
                                FROM TABLEB B
                                LEFT OUTER JOIN
                                INSERTED I
                                ON B.SNO = I.SNO
                                WHERE I.SNO IS NULL
                    RAISERROR('S.nos are missing in tableA which are present in tableB',16,1);
                    ROLLBACK;
                end     
            END
        GO
    
    

    Test if the trigger fires when the Sno are missing

    
    
    -- Errors with message as the SNO is missing
    update TABLEA
    set PartNo = 'newPartNo'
    where SNO = 'SnoNOTinB'
    
    -- works no errors as both SNOS are present in tableB
    update TABLEA
    set PartNo = 'new one'
    where SNO in ('GR7764', 'GR7765')
    
    -- Also you dont have to join with tableB now and modify query as below
    UPDATE A
    set A.Mat_No ='"+ Mat_No+"',WO_No='"+WO_No+"',
    Code = '"+Code+"',Desc = '"+Desc+"',
    Center='"+Center+"',
    Date='"+Date+"',
    Remarks='"+Remarks+"' 
    FROM TableA A                   
    WHERE A.Status = 'IN' 
    
    

    Finally clean up the code

    
    
        drop table TABLEA
          drop table TABLEB
    
    
  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

I have two tables, where only one column is the same. I am trying
I have two tables that I want to join into one table and use
I have two tables - `employee` and `department`. 1. `employee` table contains column id,employee
I have two tables, one parent and one child table. Child will have many
I have two tables having 1 to 1 relationship. One table called Person and
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two tables, one parent Point and one child PointValue, connected by 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.