- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi,
I want to create T-SQL stored procedure that will do the following task :
I have 2 tables. A and B. A and B have 4 fields in common. The fields are named F1, F2, F3 and F4. B is the reference table that contain an ID (say K1 as the field name) and the 4 fields (Fx). A is the data table that contains both the foreign key K1 and also the fields (Fx). So basically, I can do a select on table A and get by using relatinal data the related value of F1, F2, F3 and F4 using the foreign key of A.K1 and primary key of B.K1. But B is so big (millions records), I want to remove the relational for specific queries that has to be very fast and a so select on one table only (A). So periodically, I want to execute a stored procedure that will take the data from B and put them in A using both a SELECT (to get the related data) and an UPDATE (to update the table A).
Look this pseudo code, I want this in TSQL
ARECORDSTOBEUPDATED = SELECT ALL RECORDS FROM A THAT DO NOT CONTAIN F1 VALUE (this means we did not normalized it yet)
( FOREACH MAINDATAROW IN ARECORDSTOBEUPDATED DO:
REFERENCEROW = SELECT TOP 1 FROM B WHERE B.K1 = MAINDATAROW .K1
UPDATE MAINDATAROW WITH REFERENCEROW DATA (F1, F2, F3, F4)
)
This is quite simple, but I really don't know how to achieve this.
Thanks a lot in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2006-11-21 at 08:05:39ID: 17988120
update a
SET F1 = B.F1, F2 = B.F2, F3 = B.F3, F4 = B.F4
from A
join B
on A.K1 = B.K1
and A.F1 IS NULL