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 |
|
cutever
Starting Member
32 Posts |
Posted - 2002-05-29 : 05:25:36
|
| I have a excel file called MemberExcelID MemberCode JoinDate RegionID RegionName1 11111 12/01/2002 T K.TERENGGANU2 22222 12/01/2002 K KUALA LUMPUR3 33333 12/01/2002 A ALOR SETAR4 44444 12/01/2002 S SELANGOR5 55555 12/01/2002 M MELAKA6 66666 12/01/2002 P PENANG7 77777 12/01/2002 J JOHORI would like to transform the data from excel into SQL SERVER table. I have two (2) table tbl_Member and tbl_Region. If I transform directly, tbl_Member.RegionID will keep the data as (T,K,A,S,M…..). I want all the Region Info keep in separate table and tbl_Member only keep the Region ID like (1,2,3,4….) Do have any simple way to transform the above info into the result as following.tbl_Member----------------------MemberID MemberCode JoinDate RegionID -------------------------------------------------------------------------------1 11111 12/01/2002 12 22222 12/01/2002 23 33333 12/01/2002 34 44444 12/01/2002 45 55555 12/01/2002 56 66666 12/01/2002 67 77777 12/01/2002 7tbl_Region------------------------MemberID RegionName----------------------------------------1 K.TERENGGANU2 KUALA LUMPUR3 ALOR SETAR4 SELANGOR5 MELAKA6 PENANG7 JOHORHope someone can help me. Thank You !Ver |
|
|
jasper_smith
SQL Server MVP & SQLTeam MVY
846 Posts |
Posted - 2002-05-29 : 07:05:22
|
Basic Steps1)Define An Excel connection for your spreadsheet2)Define 2 SQL connections to your database3)Create a transform task between Excel and one of your SQL connections4)Choose tbl_Member as destination Table5)On transformation tab delete all mappings and create a new Copy Column mapping for ID->MemberID,MemberCode->MemberCode and JoinDate->JoinDate6)Goto the Lookup tab and create a lookup called GetRegion with a query ofSELECT RegionIDFROM tbl_RegionWHERE (RegionName = ?)7)Go back to the transformation tab choose RegionName from the Source and Region ID from the Destination and click on New and choose ActiveX Script8)Click on Properties on the first tab of this new task and it will show you the Script Editor9)Change the script to read'**********************************************************************' Visual Basic Transformation Script'************************************************************************' Copy each source column to the destination columnFunction Main() DTSDestination("RegionID") =DTSLookups("GetRegion").Execute( DTSSource("RegionName")) Main = DTSTransformStat_OKEnd FunctionThat's basically it. What you've done is define a lookup that accepts the RegionName as a parameter and gets the RegionId and sets this in the tbl_Member table(And don't call your tables tbl_* this isn't Access )HTHJasper Smith |
 |
|
|
cutever
Starting Member
32 Posts |
Posted - 2002-05-29 : 23:23:35
|
quote: 2)Define 2 SQL connections to your database6)Goto the Lookup tab and create a lookup called GetRegion with a query ofSELECT RegionIDFROM tbl_RegionWHERE (RegionName = ?)
Why I should define 2 SQL Connection ? I have many different Regions, so, this is very difficult for me to select one by one, by using the following method.SELECT RegionID FROM tbl_Region WHERE (RegionName = ?)Lookup Query also not accept it.Please.....help !!!Ver |
 |
|
|
cutever
Starting Member
32 Posts |
Posted - 2002-05-29 : 23:49:11
|
I got it !!! Thank You Very Much !!!! Ver |
 |
|
|
|
|
|
|
|