Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Load CSV file into temptable Expand / Collapse
Author
Message
Posted Monday, October 15, 2012 5:57 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 10:12 AM
Points: 235, Visits: 974
Hi Experts,

can some one share script which loads data into temptable from csv file.?

Post #1372995
Posted Monday, October 15, 2012 6:24 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:02 PM
Points: 5,563, Visits: 24,696
You can learn how by going to this link.

http://msdn.microsoft.com/en-us/library/ms141209(v=sql.100).aspx


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1373000
Posted Monday, October 15, 2012 6:43 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 10:12 AM
Points: 235, Visits: 974
Thanks for the reply ron,

I am expecting a script, not thru GUI

Thanks again :)
Post #1373003
Posted Monday, October 15, 2012 7:05 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:02 PM
Points: 5,563, Visits: 24,696
Sqlism (10/15/2012)
Thanks for the reply ron,

I am expecting a script, not thru GUI

Thanks again :)


In the previous link note the following:

You can also decide whether to save the package to SQL Server or to the file system. If you select to save the package, you must also specify a package protection level. For more information about package protection levels, see Setting the Protection Level of Packages.

After the SQL Server Import and Export Wizard has created the package and copied the data, you can use the SSIS Designer to open and change the saved package.



If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1373005
Posted Monday, October 15, 2012 11:24 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 31, 2014 9:19 PM
Points: 1,128, Visits: 1,162
Let me know if this helps..

CSV FILE : Test.csv
a,b
1,A
2,B
3,C


Then in the SSMS :
create table #test(a int,b varchar)

BULK INSERT #test1
FROM 'C:\Test.csv'
WITH
(
FIELDTERMINATOR =',',
ROWTERMINATOR =' ',
FIRSTROW = 2
)

Edit :ROWTERMINATOR = '\ n'

This is one way to load from csv file to a table ...
FIRSTROW is a check to filter out loading headers..


~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1373030
Posted Tuesday, October 16, 2012 10:41 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 10:12 AM
Points: 235, Visits: 974
Thanks for the script demonfox!

It works for me.

is there anyway, we can load data without declaring coulmn names and data types(data type is not the issue for me)

My csv file has first row as column names
Post #1373398
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse