Solved

SQL UPDATE

Posted on 2013-01-04
5
220 Views
Last Modified: 2013-01-04
Below code is only updating 1 record. Should be updating the 50 records in the temp table.

update #State
SET StateName = StateProvinceDesc
from StateProvince
WHERE  StateCode = StateProvinceCode

Not sure what the problem is.
0
Comment
Question by:thayduck
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:tim_cs
ID: 38744985
Are you sure there are 50 records that match?  Try writing it this way.

Update s
SET s.StateName = sp.StateProvinceDesc
FROM #State s
   INNER JOIN StateProvince sp
      ON s.StateCode = sp.StateProvinceCode
0
 

Author Comment

by:thayduck
ID: 38745028
#State
AL      USA      AL-USA      Alabama
AR      USA      AR-USA      AR-USA
AZ      USA      AZ-USA      AZ-USA

StateProvince
2      AK         Alaska              USA
1      AL         Alabama              USA
3      AR         Arkansas              USA
4      AZ         Arizona              USA
5      CA         California         USA
6      CO         Colorado              USA
7      CT         Connecticut      USA

You get same results as me, 1 record updated, Alabama.
0
 
LVL 15

Accepted Solution

by:
tim_cs earned 100 total points
ID: 38745072
What are the datatypes for the fields, do they match?  Is it always just Alabama that gets updated?

What happens if you run this one?  

Update s
SET s.StateName = sp.StateProvinceDesc
FROM #State s
   INNER JOIN StateProvince sp
      ON s.StateCode = sp.StateProvinceCode
      AND s.StateName <> sp.StateProvinceDesc
0
 

Author Comment

by:thayduck
ID: 38745103
I am re-keying the State Province records into the StateProvince table.
I re-keyed 4 records and reran query. Now those records are being updated correctly.
Visually they all look right, so I am not sure why re-keying over the state code in the table is  causing the records to now be updateable. ???????????????????????????????????????????????

I will let you know if this is all fixed after I re-key all records.
0
 

Author Closing Comment

by:thayduck
ID: 38745342
Re-Keyed records and everything is fine now.

Last time I do a copy and paste when creating records in a table.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now