Showing posts with label CSV file. Show all posts
Showing posts with label CSV file. Show all posts

Thursday, February 2, 2017

Importing a CSV text file into MS Access - Part 1

Importing a text file into MS Access very easy as it is completely wizard driven. But the text file needs pre-processing before importing as a text file has only one data type for any of the columns imported. When you generate a text file
The version of MS Access used is Microsoft Access 2016 MSO 32-bit which is a part of the Office 365 subscription.

The import is completely wizard driven as you see in the following steps. I will be using the same text file that I generated from the Norhtwind database on my SQL Server 2012. The details of this are available in this post.

This post considers importing a text file into  MS Access table using Wizard and the type of error produced.

The following query was used to provide the data for the text file:
=====
SELECT Products.ProductName, [Order

Details].UnitPrice, [Order Details].Quantity, Orders.OrderDate, Orders.RequiredDate
FROM     [Order Details] INNER JOIN
                  Orders ON [Order Details].OrderID = Orders.OrderID INNER JOIN
                  Products ON [Order Details].ProductID = Products.ProductID
Where [Order Details].UnitPrice>100

====
This is a sample of the file FFD.txt generated (just two rows reproduced).
ProductName,                   UnitPrice,  Quantity,   OrderDate,                   RequiredDate
Côte de Blaye,                  210.8,         49,            1997-01-23 00:00:00,  1997-02-20 00:00:00
Thüringer Rostbratwurst, 123.79,       12,            1997-10-09 00:00:00,  1997-11-06 00:00:00

The next images show the various steps of the wizard:

Highlight the default table Table 1 and right click to access the import of a text file as shown below.


 The Get External Data - Text File is displayed as shown. Accept the default to import the text file to a new table in the current database option after Browsing to bring in the FFD.txt file stored in your folder / file system.



The data is immediately (small sample) brought into the Import Text Wizard as shown.

 Accept the first option as the file is comma delimited. Place check mark for 'First Row Contains Field Names'.  


Click Next. Click Advanced to see the field specification. Click OK.

Click Next.  Allow Access to provide a Primary Key
 Provide a name for the new table.

 Click Finish. The import is finished and you can save the steps you took to import. As you can see there were data that did not come through cleanly and there were import errors.


MS Access created two tables, the table in which successfully imported data was saved and another table with _ImportErrors appended containing the fields that did not make as shown.


This is not a successful import of the data as two of the columns did not make it to the import. In Part 2 modifications to the import process that would bring in the data correctly.

Tuesday, January 31, 2017

Importing a CSV file into SAP's SQL Anywhere 17

Importing data in csv files, from excel files and web pages are often required. Each software vendor have their own tools to import such data. In SAP's SQL Anywhere 17 you can import data in text files using the Interactive SQL tool.

For working with this post it is assumed you have installed SAP's SQL Anywhere 17 and you have an available csv file. For this post I will be using a text file created using the export-import wizard tool from a table in the Northwind database on a SQL Server 2012. You can of course use a suitable text file. Generating the FFD.txt file is described here (http://hodentekmsss.blogspot.com/2016/12/creating-csv-file-from-sql-server-2012.html).

The following is the procedure to import the text file into sql Anywhere 17.

From All Programs in Windows 10 click on Interactive SQL under SQL Anywhere 17.


This brings up the window 'Connect to a SQL Anywhere Database'.

Fill in the authentication information (dba\sql) and click Browse on the ODBC Data Source name and pick SQL Anywhere 17 Demo.

Click Tools and Test Connection to ensure you are connected.



SAP_1

Click Connect and you are connected to the demo database. Your personal server is running now as shown.

SAP_2


The Interactive SQL window should now be up with connection established to the demo database as shown.

SAP_3

Click Data | Import... to open the Pop-up window Import Wizard as shown.


SAP_4

Choose the default 'In a text file' and click Next to open the 'Select the file to import' page of the Import Wizard as shown.

SAP_5
Browse and locate the text file on your computer.

 Click Next.

Click Next.  In the next window use Comma as the field separator and insert check mark for 'The first line contains column names' as shown.

Click Next. The 'Use this panel to associate a database column with each imported column. Change datatype of the two date columns to 'time' from 'varchar'. You may highlight a column and change the data type, if it is not what you want. Here in is the drop-down for the Order Date.



Click Next. The "Where do you want to save data?" window is now open with two options. Choose to get the data into a new table and change default name of table to FFDImport. 

Click Import. The data gets imported.


The text data gets imported into the table FFDImport.

Close the Import Wizard.

The Interactive SQL window shows the SELECT * from the new table as shown.

SAP_11

Although the import was successful, the time related columns did not come through correctly. In the next post we shall see if we can correct this. For this post the 'varchar' data type for the OrderDate and RequiredDate were replaced by the 'time' data type in the Interactive SQL's, import data wizard.

The table is now visible in the SQL Explorer as shown.

SAP_12.png









When Identity Security Becomes a Wall — Not a Shield

After a breach that forced a reset of my digital identity, I hit a roadblock I never anticipated: multi-factor authentication (2FA) locked m...