Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2006, 12:39 PM
Authorized User
 
Join Date: Sep 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Importing CSV file into SQL from Web

Hi..
Source File: http://www.webname.com/files/log.csv
Destination: SQL Server to process the rows

I am trying to get the above file into SQL server to query the data. The above file takes a username and password.

Do I need to create a linked server?

The only way i can think of at present is to copy the file onto the server(by FTP) and query it something like this.

select * from OpenRowset('MSDASQL'
 ,'driver={Microsoft Text Driver (*.txt; *.csv)}
 ;DefaultDir=C:\;'
 ,'select * from log.csv')

Any help or pointers appreciated
Dan






 
Old November 14th, 2006, 09:29 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Copy the file to a place where SQL Server can see it... then, do a BULK INSERT. See Books OnLine for details.

--Jeff Moden
 
Old November 16th, 2006, 05:41 AM
Authorized User
 
Join Date: Sep 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the reply
regarding the below I would like to declare a variable of the location, namely have the path passed in at runtime.

select * from OpenRowset('MSDASQL'
 ,'driver={Microsoft Text Driver (*.txt; *.csv)}
 ;DefaultDir=C:\;', 'select * from log.csv')

/--------------This is what I am trying
declare @file varchar(100)
set @file = 'C:\'

select * from OpenRowset('MSDASQL'
 ,'driver={Microsoft Text Driver (*.txt; *.csv)}
 ;DefaultDir=@file;'
 ,'select * from log.csv')


this does not seem to work, any help appreciated



 
Old November 20th, 2006, 01:23 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Sorry... I don't use OpenRowSet... it's too slow for me... I just copy the file to an import staging area and do a nasty fast bulk insert. What the heck... disk space is cheap and if I need to reload for some reason... it's already local.

--Jeff Moden
 
Old December 14th, 2006, 04:46 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check where the parameter "c:" is. Are you thinking this is your local client c: drive or the server c: drive. Your command is executed relative to the server you established a connected to. Make sure your on the right "C:" drive/server. You may be pointing to the wrong place and thus not working.

 
Old December 14th, 2006, 07:25 PM
Authorized User
 
Join Date: Sep 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks
good point, will have a look

 
Old December 15th, 2006, 09:48 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Bulk Insert! http://p2p.wrox.com/topic.asp?TOPIC_ID=53130

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing data from a CSV file? kr33 SQL Server 2000 26 January 3rd, 2007 02:38 AM
Importing csv file to SQL Server Using VB.Net ninel General .NET 0 August 8th, 2006 02:11 PM
Importing a CSV file into SQL rsmuts ASP.NET 1.0 and 1.1 Professional 2 July 24th, 2006 10:14 AM
Importing data from CSV file g_vamsi_krish ASP.NET 1.0 and 1.1 Basics 2 May 23rd, 2006 01:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.