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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:29:07+00:00 2026-05-28T19:29:07+00:00

I am new to SQL and trying to achieve something. I have a table

  • 0

I am new to SQL and trying to achieve something.

I have a table having fields like:

CustId   Fname   Lname    Address1    Address2  Zip    State  LoadDate   Flag
1        John     Leo      xxx        xxx       34532    VA    1/1/2012   Y
2        Mike     Saunder  xxx        xxx       94090    CA    1/1/2012   Y

Everytime I insert a new record it will set its flag to Y but lets say if any of the record value changes then new one will be set to Flag Y and old one to N. So for example if Mikes address1 is changed.

CustId   Fname   Lname    Address1    Address2  Zip    State  LoadDate   Flag
1        John     Leo      xxx        xxx       34532    VA    1/1/2012   Y
2        Mike     Saunder  xxx        xxx       94090    CA    1/1/2012   N
3        Mike     Saunder  rrr        xxx       94090    CA    2/1/2012   Y
  • 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-28T19:29:07+00:00Added an answer on May 28, 2026 at 7:29 pm

    Assuming that you’re trying to say that the Fname/Lname pair is a unique key that lets you match rows:

    declare @Folks as table ( CustId int, Fname varchar(10), Lname varchar(10),
      Address1 varchar(10), Address2 varchar(10),
      Zip varchar(9), State varchar(2), LoadDate date, Flag char(1) )
    insert into @Folks ( CustId, Fname, Lname, Address1, Address2, Zip, State, LoadDate, Flag ) values
      ( 1, 'John', 'Leo', 'xxx', 'xxx', '34532', 'VA', '1/1/2012', '-' ),
      ( 2, 'Mike', 'Saunder', 'xxx', 'xxx', '94090', 'CA', '1/1/2012', '-' ),
      ( 3, 'Mike', 'Saunder', 'rrr', 'xxx', '94090', 'CA', '2/1/2012', '-' )
    
    -- Before setting the Flag.
    select * from @Folks
    
    -- Computing a flying flag rather than using a stored value.
    select *, case when LoadDate = ( select MAX(LoadDate) from @Folks as S where S.Fname = O.Fname and S.Lname = O.Lname ) then 'Y' else 'N' end as 'FlyingFlag'
      from @Folks as O
    
    -- Updating all stored values.  Every bloody row.
    update @Folks
      set Flag = case when LoadDate = ( select MAX(LoadDate) from @Folks as S where S.Fname = O.Fname and S.Lname = O.Lname ) then 'Y' else 'N' end
      from @Folks as O
    
    -- Showing the result.
    select * from @Folks
    

    EDIT:
    I still think this is not the direction you want to be heading. For example, it doesn’t gracefully accomodate more than one update per customer per day unless you rely on the CustId to be a tie breaker.

    A marginally better solution would be to replace Flag with a PreviousId field that is NULL in the first row for a customer and in later rows contains the CustId of the row that is being superseded. That links together the changes for each customer and provides a well defined order in the event that a customer is updated repeatedly on a single date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to MVC3 Razor - linq to sql having spent some time trying to
Suppose I have an SQL table entitled Facility which looks like this: || FacilityID
I'm relatively new SQL queries, and I'm trying to join two tables in order
I'm new to SQL and database design and trying to work out if the
I am fairly new to sql and I've run into an error while trying
I'm trying to add new entries to an sql database using php, i can
I'm trying to translate this SQL sentence to LINQ but I'm very new in
I'm new to OOP and trying to define a set of public prepared SQL
What's up with JNDI names? I'm trying to get a javax.sql.DataSource using the new
I am new to mysql and have an My sql query wrote and tryin

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.