?
Solved

Query to cross reference two text fields and update data

Posted on 2005-02-25
4
Medium Priority
?
997 Views
Last Modified: 2012-05-05
Hi,

I have some data in an excel spread sheet for staff addresses. I also have a SQL database table with staff information on and am trying to come up with an automated process to import the data.

So far I have moved the excel data to a new temporary database table with all the columns of the excel file. I simply copied the excel data into the tempory SQL table.

My Existing Staff database table and the temporary table contain the following fields:-

Forename, Surname AddressLine1,AddressLine2,AddressLine3,TownCity,PostCode

Since the temporary table does not contain address records for ALL members of staff in my Staff database table I am unable to simply run a sort by forename and surname to copy and paste data.

I beleive the best way to update the data would be to cross reference both the Forename and Surname fields on the two tables and then update the adress data in table StaffData from that contained in TEMPTABLE

Does anyone know an update query (or anything similar) thatI can run to achieve this?

Thanks for reading,

Si.

0
Comment
Question by:BigSi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 100 total points
ID: 13401731
you'll be much better off with a join on an employee number are you sure
you havn't got several employees with the same name?
 
0
 
LVL 2

Author Comment

by:BigSi
ID: 13401768
There are no employees with the same Surname and Forename. I am unable to link using emplyee number since that data is not present in the excel file.

However, I have come up with a different sollution,

I created a 'make table' query that creates a new table based on the contents of the two tables being cross referenced.

I then plan to replace the table origional staff table with the newly created table.

I will post to say how I have got on.
0
 
LVL 13

Accepted Solution

by:
KarinLoos earned 400 total points
ID: 13401774
I agree with Lowfat,  you would be better off 'crossreferencing' on the employeeID / employeeNumer , Social Security nr or someother totally unique field to an employee.
however  :
Update    StaffData
set     Addressline1  =  b.AddressLine1 ,
         AddressLine2  = b.AddressLine2,
         AddressLine3  = b.AddressLine3,
        TownCity         = b.TownCity,
         PostCode        = b.PostCode
FROM   StaffData                           a
JOIN    TEMPTABLE                        b ON (b.Forename = a.Forename
                                                     AND  b.Surname  = a.Surname )

0
 
LVL 2

Author Comment

by:BigSi
ID: 13401830
Thanks KarinLoos - The query worked a treat!

I never knew you could assign a table name an alias such as A and B so I've learnt something else there.

Thanks very much for you help!

It would have been usefull to have a single ID field in both tables that were the same, but the data was being imported from a seperate system that had no other field in common apart from forename and surname..

Thanks again,
Si.



0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

752 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