importing data from a spreadsheet that contains phone numbers, zip codes and other similar string...

13
Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation via a web browser, right-click and choose “Fu ll Screen” before proceeding. Click mouse or press space bar to continue. esentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington Un contact Dr. Ross for permission to use in other settings.. e Sister Cities Database velopment Project

Upload: kaitlyn-gange

Post on 31-Mar-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data

that looks like a numberIf you came to this presentation via a web browser,

right-click and choose “Full Screen” before proceeding.

Click mouse or press space bar to continue.

• This presentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington University. Please contact Dr. Ross for permission to use in other settings..

The Sister Cities Database Development Project

Page 2: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Wizards are Wonderful, but …

Complications are not uncommon with import Wizards. The Wizard interprets the data according to the rules it has been programmed with. Sometimes that interpretation incorrect.

One such problem can occur when the Excel data contains strings that look like numbers, but are not actually numbers. For example, telephone numbers or ZIP codes. The Wizard will define the phone number in the import table as a numeric field in the database table it creates. The phone numbers and the ZIP codes get corrupted in the process.

Page 3: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Solutions to the Wizard Problem

Solutions to this particular problem may include…

1. Exporting the data from the Excel spreadsheet to a text file (e.g. NotePad) first, then importing the data from the NotePad document, rather than directly from the spreadsheet.

2. Modifying the data in the Excel spreadsheet so it is clearly a string. For example, you could add “x” to the beginning of every phone number or ZIP code: X555-1234. If you modify the data, of course you must undo the alteration after the data has been imported.

The following slides show how Method 1 might be implemented. For extra practice, you can try Method 2 on your own.

Page 4: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Export the Spreadsheet

2. File tab – Save As commanda. Give the file a recognizable name, e.g., WorkersTab

b. Save as type: Text (Tab delimited)

c. If there aremultiplesheets, adialog boxwill ask if itis OK to save onlyactive sheet– click OK

Page 5: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

3. Import the dataa. Right-click Database name; choose Tasks; choose

Import Data…; click Next > on the splash screen

b. Choose the Data Source (Flat File Source) and browse to locate the file

c. Note thesesettings

d. click Next >twice

Import the Data

Page 6: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Import the Data

3. Import the datae. Choose the

destination then click Next >

Page 7: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Import the Data

3. Import the dataf. Select Source

Table g. Click Edit

Mappings…(see next slide)

Page 8: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Import the Data

3. Import the datag. Click Edit

Mappings… change as req., click OK,then Next >

h. {on the next screen} Choose Run Package immediately; click Next >

i. {on the next screen} Click Finish

Page 9: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Import the Data

3. Import the dataj. Read the

report, then Close.

Page 10: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Verify the Results

4. Inspect the table (right-click table name, choose Select Top 1000 Rows)

a. Data in expected columns

b. Numeric data format, ensure no loss

c. Character data, check for truncation

Page 11: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Analyze Data in Import Table

5. Modify the SELECT query created in Step 4 …a. Remove “TOP 1000”

b. Add functions to determine maximum length of strings and maximum value of numbers:

SELECT MAX(LEN([LastName])) AS [LastName] ,MAX(LEN([FirstName])) AS [FirstName] ,MAX(LEN([MidName])) AS [MidName] ,MAX([AnnualPay1000]) AS [AnnualPay1000] ,MAX(LEN([DepartmentName])) AS [DepartmentName] ,MAX(LEN([Rank])) AS [Rank] ,MAX([BudgetAuthorityIn1000]) AS [BudgetAuthorityIn1000] ,MAX([PersonalStaff]) AS [PersonalStaff] ,MAX(LEN([MailCode])) AS [MailCode] FROM [createdbexample].[dbo].[WorkersTab]

Page 12: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation
Page 13: Importing Data from a Spreadsheet that contains Phone Numbers, ZIP Codes and other similar string data that looks like a number If you came to this presentation

Create and Populate the Final Table

As with the method demonstrated in …“ImportingData - General Case (including data with large strings and integers)”

… you should then build a final table and copy the data from the temporary import table to the final table.

See “ImportingData - Moving Data the Import Table to the Final Table”

for details.