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 154635

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:00:50+00:00 2026-05-11T10:00:50+00:00

This is a follow up question to this one: Query examples in a many-to-many

  • 0

This is a follow up question to this one:

Query examples in a many-to-many relationship

regarding updating the junction table. To do this, I would have to use both key values in the junction table, in the WHERE clause.

Users       UserAddresses     Addresses =======     =============     ========= FirstName   UserId            City LastName    AddressId         State                               Zip 

In this example, for instance, say I wanted to update the AddressId field in the UserAddresses table, because a user changed his address. I would have to use both the existing UserId and the address AddressId in the update WHERE clause.

I’m using a stored procedure, and passing in UserId and the new AddressId as parameters.

I’ve tries this:

CREATE PROCEDURE dbo.test ( @UserId int, @AddressId int ) AS create table #temp     (     UserId int not null,     AddressId int not null     )     insert into #temp select UserId, AddressId from UserAddresses where UserId = @UserId  update UserAddresses set AddressId = @AddressIdD WHERE (UserId+AddressId in #temp table = UserId+AddressId passed in as parameters)?? 

I’ve tried all sorts of combinations, but I can’t seem to get the syntax right.

The UserId passed in, would ofcourse be the same as the one in the UserAddresses table, but this is just me trying some things. The WHERE clause is where it seems to go wrong.

Any thoughts?

  • 0 0 Answers
  • 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. 2026-05-11T10:00:50+00:00Added an answer on May 11, 2026 at 10:00 am

    This actually looks like a many-to-one relationship. If it’s not you’ll need the old address id as well as the new address id and user id to make the change. If it’s a many to one relationship then a simple update should work since only one user id/address id pair will exist for each user id:

    update UserAddresses set AddressId = @AddressId where UserId = @UserId 

    If it truly is a many-to-many relationship you need to find the existing pair out of many possible ones and update that one — that’s where you’ll need both the new and old address ids in addition to the user id.

    update UserAddresses set AddressId = @NewAddressId where UserId = @UserId and @AddressId = @OldAddressId 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Option 1 will be slower than Option 2. Lambda expressions… May 11, 2026 at 11:13 am
  • added an answer You asked for a practical example of volatile member functions.… May 11, 2026 at 11:13 am
  • added an answer Ian's solution seems like a pretty good long term solution,… May 11, 2026 at 11:13 am

Related Questions

This is a follow-up question to this one . Take a look at these
This is a follow up question to This Question . I like (and understand)
This is somewhat of a follow-up question to this question . Suppose I have
This is kind of a follow-up question to this . When I'm debugging threads
This is a follow up to this question , where I didn't get any
This is sort of a follow-up to this question . If there are multiple
This is a follow-up to the question: Should the folders in a solution match
This is a follow-up to my question from yesterday . I have Scott Meyers'
This is a follow up to a question I just posted. I'm wondering how
This is a follow-up to a previous question I had about interfaces. I received

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.