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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:00:44+00:00 2026-05-12T16:00:44+00:00

Due to an added field in a MsSql Database, I have to change the

  • 0

Due to an added field in a MsSql Database, I have to change the records in a table from NULL to something more usefull.

I’ve got a table with addresses. Because customers have multiple addresses we’d like to mark certain addresses as default and others as something like shipping.

How can I, using a query, change only the first of every address to “Default” and every other to “Shipping”? Every address has a foreign key relation to the Customers table thru a CustomerId.

It doesn’t really matter which one is made default, as long as one is default and the rest something else. Just to be able to edit the default address in thru the UI of our application and show a table with every other adress.

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

    Assuming that Address table uses a surrogate primary key that is integer based (like an IDENTITY column), and if you really don’t care which one gets marked as DEFAULT, you could do something like the following (which updates the row with the lowest integer value as the DEFAULT).

    DECLARE @Addresses TABLE
        (
          AddressID INT ,
          CustomerID INT ,
          AddressType VARCHAR(8)
        )
    
    INSERT  INTO @Addresses
            ( AddressID ,
              CustomerID ,
              AddressType
            )
            SELECT  1 ,
                    1 ,
                    NULL --Client 1 has 3 addresss
            UNION ALL
            SELECT  2 ,
                    1 ,
                    NULL
            UNION ALL
            SELECT  3 ,
                    1 ,
                    NULL
            UNION ALL
            SELECT  4 ,
                    2 ,
                    NULL --Client 2 has 1 addresses
            UNION ALL
            SELECT  5 ,
                    3 ,
                    NULL --Client 3 has 2 addresses
            UNION ALL
            SELECT  6 ,
                    3 ,
                    NULL
    
    SELECT  *
    FROM    @Addresses a
    
    --update an arbitrary address ASSUMING that you used an integer for a surrogate primary key
    UPDATE  @Addresses
    SET     AddressType = CASE WHEN AddressID IN ( SELECT   MIN(AddressID)
                                                   FROM     @Addresses a
                                                   GROUP BY a.CustomerID ) THEN 'Default'
                               ELSE 'Shipping'
                          END
    
    
    SELECT  *
    FROM    @Addresses a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to the last release of the adMob package, I have added the MessageUI
I have a table called People one of the columns is an xml field
I have an sql server view which I've recently added a field to the
Due to an incident a few months prior, thousands of author_ids have been deleted
Due to a number of constraints that I won't get into, I have to
Due to a harddrive crash, I lost my SQL server database files for a
I would like to use new table component added to JasperReports 3.7.2 with grails
We have a local server with an access database which feeds data to clients
I have Assignment due in which i'm stuck on a question. Add a Sales
How would you go about determining how much time was added due to working

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.