Import FoxPro database into SQL Server [duplicate] - sql

How can you import a foxpro DBF file in SQL Server?

Use a linked server or use openrowset, example
SELECT * into SomeTable
FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver;
SourceDB=\\SomeServer\SomePath\;
SourceType=DBF',
'SELECT * FROM SomeDBF')

I was able to use the answer from jnovation but since there was something wrong with my fields, I simply selected specific fields instead of all, like:
select * into CERTDATA
from openrowset('VFPOLEDB','C:\SomePath\CERTDATA.DBF';'';
'','SELECT ACTUAL, CERTID, FROM CERTDATA')
Very exciting to finally have a workable answer thanks to everyone here!

http://elphsoft.com/dbfcommander.html can export from DBF to SQL Server and vice versa

What finally worked for us was to use the FoxPro OLEDB Driver and use the following syntax. In our case we are using SQL 2008.
select * from
openrowset('VFPOLEDB','\\VM-GIS\E\Projects\mymap.dbf';'';
'','SELECT * FROM mymap')
Substitute the \\VM-GIS... with the location of your DBF file, either UNC or drive path. Also, substitute mymap after the FROM with the name of the DBF file without the .dbf extension.

This tools allows you to import to and from SQL Server.
http://www.download3000.com/download_17933.html

Related

Import Access Table to MS sql using openrow set

Im trying to import an access table to sql using openrowset function. I can get it to work with excel but have not manged to get it working with Access. I've a load of tables which would be time consuming to do via wizard. This is the code I have so far
select * into input_2013.[sample] from openrowset('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=W:\Projects\Sample.xlsx;HDR=yes', 'SELECT * FROM [sheet1$a2:t]');
Your code is for Excel, maybe if you posted the code you had tried so far for Access and not managed to get working it would help?
You could try something along these lines:
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'W:\Projects\test.mdb';'admin';'', MyData);
Note that you need to provide a username/ password as well as the file name.

SPSS syntax to connect to database

I've successfully connected to a IBM DB2 database in SPSS using the connection wizard. However, I haven't found a working method to do this using SPSS syntax. Has anyone any experience with this?
Normally you'd access it via this Syntax:
GET DATA /TYPE = - insert one of these types - ODBC,OLEDB,XLS,XLSX,XLSM,TXT
Whichever is the type that you wish to access, you can also use SQL within the SPSS syntax editor. This is how I connect to my database from the syntax:
GET DATA
/TYPE=ODBC
/CONNECT='DSN=MAVSQL;Description=SQL;UID=;APP=IBM SPSS Products: Statistics '+
'Common;WSID=MAVNEW;DATABASE=Players;Trusted_Connection=Yes'
/SQL='SELECT Id, Faction, Active, Level, Name, Allignment, CurQuest, '+
'PrevQuest, DeathCount, LastDeath, LastLogon, Created, Class, RacAB, '+ 'Comments, Test, Age, RealName, Email FROM dbo.DSOL'
/ASSUMEDSTRWIDTH=255.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.
Hope that helps, I know the database I accessed is a SQL database but perhaps you can use the same methodology to access your IBM DB2 database.
Besides pasting the syntax shown in the last panel of the Database Wizard, which includes the connection string and the SQL that goes with the GET DATA command, you can save the query as an spq file from that last panel and use that again in the Database Wizard by choosing Edit Query in the first step.

tsql : outputting each record to their own text file

is there a simple way to just output each record in a select statement to write to its own file?
for example, if you have the tsql query in sql server 2005,
select top 10 items, names + ':' + address from book
and you ended up with 10 text files with the individual name and addresses in each file.
is there a way to do this without writing an extensive spWriteStringToFile procedure? I'm hoping there is some kind of output setting or something in the select statement.
thanks in advance
SQL returns the result set first, there's no opportunity in there for writing records to specific files until afterwards.
Being SQL Server 2005, it's possible you could use a SQLCLR (.NET 2.0 code) function in a SQL statement without having to make a separate application.
In SSMS, you can do a results to file, but that wouldnt split each record out into its own file. I pretty sure you cannot do this out of the box, so it sounds like you will be rolling your own solution.
You'd do this in some client, be it Java, VBA or SSIS typically.

How to insert the contents of a text file into a table in SQL Server

I have several files (they are XML but that's not important) that need to be inserted into an existing SQL table (i.e. I didn't design it.) The table looks like this.
ReportType
ID (int) <- identity
Name (varchar(32))
TransformXSLT (nvarchar(max))
Normally I would do:
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', '<lots><of><xml><goes><here>...</lots>')
Is there any way to do:
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', {filename})
I'm using SQL Server Management Studio and Eclipse+Maven to manage the files.
BULK INSERT or OPENROWSET(BULKā€¦) are the usual options from T-SQL
After comment...
...FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB);
and the "Bulk Exporting or Importing SQLXML Documents" section here
Sorry, I've not actually tried this but MSDN says you can
Have you tried using the SQL Server Import and Export Wizard?
Go into SQL Server Management Studio. In Object Explorer, right click the database then Tasks > Import Data....
This will let you import data as a one off exercise, or let you save the resulting SSIS package and re-run it.
Give it a go.

Creating a SQL table from a xls (Excel) file

I'm trying to convert an Excel document into a table in SQL 2005. I found the link below and am wondering if it looks like a solution. If so, what would the #excel_full_file_name syntax be and where would the path be relative to?
http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-convert-Excel_to_table.html
You can use the BULK INSERT T-SQL command if you just want a pure sql solution. You have to save the file as csv/text first.
BULK
INSERT YourDestinationTable
FROM 'D:\YourFile.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
Alternatively, you can try OPENROWEST - again , a pure T-SQL solution.
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;DATABASE=D:\YourExcelFile.xls', 'Select * from YourExcelFile')
It really depends on how much control and flexibility you want, the SSIS route will have benefits over these methods.
Glancing over the code, I would expect it to be the full path name of the excel document:
For example: c:\path\to\my\excel\document.xls
I haven't installed the procedure though or run it, so I could be wrong - but that's what it appears to be at first glance.
I would suggest using an SSIS/DTS Package, to convert. It's much easier.
SSIS Excel example
** note that this example is using the wizard. you can schedule the SSIS/DTS package as a job to run, on your SQL box.
This example copies data from SQL to Excel.
But it is just a matter of swapping the OleDb providers to get it to work in the opposite direction.