Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-12-05 : 09:21:14
|
| I would like to write queries for the following problem:I have the following tables:table one:hs_code ust_code district port share848071 1220 01 06 0.0130392831238073848071 1220 01 15 0.975529250994227848071 1220 01 18 0.0114314658819652848071 1220 02 07 0.00273487477707323848071 1220 02 09 0.00779612804098788I want to map each 6 digit hs_code to 10 digit hs_code in the following table for each port in the above table table two:hs_code ust_code district8480718045 1220 018480718060 1220 018480718045 1220 028480718060 1220 02for example "848071 1220 01" in table two is related to 3 ports 06,15, and 18 in table one. all 10 digits which share the same 6 digits with ust_code 1220 in distinct 01 should map to these 3 ports with the share affiliated to them) where I can have the final product as: hs_code ust_code district port share8480718045 1220 01 06 0.01303928312380738480718045 1220 01 15 0.9755292509942278480718045 1220 01 18 0.01143146588196528480718060 1220 01 06 0.01303928312380738480718060 1220 01 15 0.9755292509942278480718060 1220 01 18 0.01143146588196528480718045 1220 02 07 0.002734874777073238480718045 1220 02 09 0.007796128040987888480718060 1220 02 07 0.002734874777073238480718060 1220 02 09 0.00779612804098788 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-12-05 : 09:51:21
|
| select ...from table1 t1join table2 t2on left(t2.hs_code,6 = t1.hs_codeand t2.ust_code = t1.ust_code==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-12-05 : 11:41:50
|
| Thank you |
 |
|
|
|
|
|