hallo Vulpes
I have a table in sql called tb1
the contents is something like this:
crse dist wintime winweight
cd 1400 67.6 60
cd 1600 71.2 58
sv 1400 69.0 59
in tbl2 in sql
crse dist partime winweight
cd 1400
cd 1600
sv 1400
I WANT TO AUTOMATICALLY UPDATE TBL2 PARTIME,WINWEIGHT WITH WINTIME ,WINWEIGHT FROM TBL1 WHERE CRSE AND DIST ARE THE SAME.
Loading

Amit ChoudharyRank #145 · 15.8K reputationPosted Dec 27, 2012, 7:33 AM EST
Amit ChoudharyRank #145 · 15.8K reputationPosted Dec 27, 2012, 6:05 AM EST
Try this query:
UPDATE
tbl2
SET
tbl2.partime = (
SELECT top 1 wintime
FROM tbl1
WHERE tbl1.crse = tbl2.crse AND tbl1.dist = tbl2.dist
),
tb2.winweight = (
SELECT top 1 winweight
FROM tbl1
WHERE tbl1.crse = tbl2.crse AND tbl1.dist = tbl2.dist
)
We don't need top 1 I just used it as precaution in case we have duplicates for both columns crse and dist.
shabeer shaik40 reputationPosted Dec 27, 2012, 7:19 AM EST
thanks for helping me out.
table 1 has a lot of duplicates example
CD 1200
CD 1400
GE 1200
GE 1400
SR 1200
SR 1400
table 1 never changes.
table 2 is new data everyday.
what is top1
shabeer shaik40 reputationPosted Dec 27, 2012, 7:53 AM EST
It works like a gift. Thank you
Sean StewartRank #5,857 · 284 reputationPosted Dec 27, 2012, 6:19 PM EST
http://decipherinfosys.wordpress.com/2007/01/31/update-data-in-one-table-with-data-from-another-table/