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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:05:17+00:00 2026-05-11T12:05:17+00:00

I have the following data : SectorKey Sector foo 1 A null 2 B

  • 0

I have the following data :

SectorKey Sector foo   1         A      null  2         B      null ...       ...    ... 1         null   a   2         null   b  2         null   c  1         null   d  2         null   e  ...       ...    ... 

I want to update column Sector when it’s null based on the value of sectorKey, ie I want Sector to be ‘A’ when SectorKey is 1 and ‘B’ when SectorKey is 2

I’ve tried this query :

update tbFoo set Sector=A.sector  from tbFoo A INNER JOIN tbFoo B ON A.SectorKey=B.SectorKey  and A.Sector is not null  and B.Sector is null 

and got this error message :

The table ‘tbFoo’ is ambiguous.

I’ve tried to alias the first tbFoo, but it doesn’t seem to be a valid syntax. I don’t understand why SQLServer complains about an ambiguous naming since I’ve got all my tables aliased.

I’ve found this thread, and I feel like I’m doing exactly the same thing as in the upvoted answer. I’ve also tried the query suggested in the accepted answer :

    update tbFoo A     set Sector =         (select Sector from tbFoo          where A.SectorKey=SectorKey and Sector is not null) 

and then SQLServer complains about an incorrect syntax near ‘A’

Any ideas on what may be happening, and to fix this? I’m using SQLServer 2008.

EDIT I’ve not shown the total data of my table. I don’t have only two cases (A and B), but rather a few thousands of cases. So an explicit case is not an option

  • 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. 2026-05-11T12:05:17+00:00Added an answer on May 11, 2026 at 12:05 pm

    Use the alias in the first part of your update query:

    update B set Sector=A.sector  from tbFoo A INNER JOIN tbFoo B ON A.SectorKey=B.SectorKey  and A.Sector is not null  and B.Sector is null 

    Otherwise it doesn’t know which instance of the table to update.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT a.PersonId FROM Abilities a JOIN Abilities b ON (a.PersonId… May 12, 2026 at 5:45 pm
  • Editorial Team
    Editorial Team added an answer Generalising away from SAP, my first thought when defining a… May 12, 2026 at 5:45 pm
  • Editorial Team
    Editorial Team added an answer Something like this: SUM(CASE WHEN ColumnName = 1 THEN 1… May 12, 2026 at 5:45 pm

Related Questions

I have the following data structure (a list of lists) [ ['4', '21', '1',
I have the following data: ExamEntry Student_ID Grade 11 1 80 12 2 70
I have the following data structure and data: CREATE TABLE `parent` ( `id` int(11)
I have the following data as input (sorted by first column): foo 1 2

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.