Monday, March 12, 2012

Retrieving data from a plain file

Dear all,
I'd need to retrieve data from a text file located in a folder from a SELECT
statement. How could I do such thing? Is it possible obtain all the data and
then show them on the screen or better, import them to a SQL table'
Best regards,
EnricIt is better to import the file using BCP/BULK INSERT/DTS etc. if you need
that data in various queries.
Otherwise, you can directly query the text file data too. Here are some
examples:
http://www.users.drew.edu/skass/sql/TextDriver.htm
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Enric" <Enric@.discussions.microsoft.com> wrote in message
news:B53B3A9D-8DDC-434B-AEF9-19F69D3B4DA4@.microsoft.com...
Dear all,
I'd need to retrieve data from a text file located in a folder from a SELECT
statement. How could I do such thing? Is it possible obtain all the data and
then show them on the screen or better, import them to a SQL table'
Best regards,
Enric|||Create a linked server to the text file and use a Schema.ini file to describ
e
the structure of the data:
http://msdn.microsoft.com/library/d...r />
_6a44.asp
http://msdn.microsoft.com/library/d...ma_ini_file.asp
This enables you to query the text file directly, as if it were a SQL table.
ML|||If your ADO.NET application needs to display records from a text file, then
you can just open the file directly using the Microsoft Text Driver. There
is no need to go through SQL Server.
Dim cn As New OdbcConnection("Driver={Micros_oft Text Driver
(*.txt;*. csv)};DefaultDir=d:\websites_\jpg\dataim
port;")
Dim cmd As New OdbcCommand ("select * From cfr.csv")
If you need the data in SQL Server, then you can use DTS to import it.
"Enric" <Enric@.discussions.microsoft.com> wrote in message
news:B53B3A9D-8DDC-434B-AEF9-19F69D3B4DA4@.microsoft.com...
> Dear all,
> I'd need to retrieve data from a text file located in a folder from a
> SELECT
> statement. How could I do such thing? Is it possible obtain all the data
> and
> then show them on the screen or better, import them to a SQL table'
> Best regards,
> Enric

No comments:

Post a Comment