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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:45:33+00:00 2026-06-06T03:45:33+00:00

I’m writing an sql statement (see below) which compares 2 serial numbers on 2

  • 0

I’m writing an sql statement (see below) which compares 2 serial numbers on 2 different tables, table1 and table2. If the serial number exists then i want another column on table1 to be updated with a ‘yes’ and if the serial number in table1 does not exist in table2 I want to update with a ‘no’

My current sql statement works perfectly and fills the column with ‘yes’ when necessary. My problem is that instead of placing a ‘no’ when the serial number doesnt exist, instead it updates to NULL. My where statement is important as I only want to compare serial numbers on both tables where the date and install match up in both tables. I do not want to compare every row. Thanks

UPDATE dbo.table1
    SET [Match] = CASE WHEN dbo.table2.[Serial Number] IS NOT NULL
    THEN 'yes' ELSE 'no' END
        FROM dbo.table1 LEFT OUTER JOIN dbo.table2
            ON dbo.table2.[Serial Number] = dbo.table1.[Serial Number]
        Where dbo.table1.[Date] = 'JAN11' AND 
              dbo.table1.[Install] = 'new' AND
              dbo.table2.[Date] = 'JAN11' AND 
              dbo.table2.[Install] = 'new'
  • 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-06T03:45:35+00:00Added an answer on June 6, 2026 at 3:45 am

    Put the WHERE conditions to JOIN’s condition:

    UPDATE dbo.table1
    SET [Match] = CASE WHEN dbo.table2.[Serial Number] IS NOT NULL
    THEN 'yes' ELSE 'no' END
        FROM dbo.table1 LEFT OUTER JOIN dbo.table2
            ON dbo.table2.[Serial Number] = dbo.table1.[Serial Number]
        AND dbo.table1.[Date] = 'JAN11' AND 
              dbo.table1.[Install] = 'new' AND
              dbo.table2.[Date] = 'JAN11' AND 
              dbo.table2.[Install] = 'new'
    

    @Baz1nga:

    The WHERE causes the rows to be filtered out, hence the setting of value(s) are not being assigned back to table1.

    Try this:

    create table tblA
    (
    x int, y varchar(10)
    );
    
    
    create table tblB
    (
    x int, some_date varchar(10), serial_number int
    );
    
    
    insert into tblA(x,y) values(1,'www');
    insert into tblB(x,some_date,serial_number) values(1,'yyy',76);
    
    print 'First update';
    update tblA
    set y = case when tblB.serial_number is not null then 'Yes' else 'No' end
    from tblA 
    left join tblB on tblB.x = tblA.x 
    where tblB.some_date = 'JAN11';
    
    select * from tblA;
    
    print 'Second update';
    update tblA
    set y = case when tblB.serial_number is not null then 'Yes' else 'No' end
    from tblA 
    left join tblB on tblB.x = tblA.x 
    and tblB.some_date = 'JAN11';
    
    select * from tblA;
    

    Output:

    (1 row(s) affected)
    
    (1 row(s) affected)
    First update
    
    (0 row(s) affected)
    x           y
    ----------- ----------
    1           www
    
    (1 row(s) affected)
    
    Second update
    
    (1 row(s) affected)
    x           y
    ----------- ----------
    1           No
    
    (1 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post

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.