Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Import of CSV file into SQL using OPENROWSET

Avatar of VicZ
VicZFlag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2005SQL
19 Comments1 Solution2498 ViewsLast Modified:
I am using the following to import CSV files into a SQL table...

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

These CSV files are generated by a program and some are created but empty.

My problem:
The query above fails when I hit an empty CSV file, either with or without column.

I also want to count the number of records

select count(col1) from openrowset...

Can the geniuses help me with a solution?  I prefer some error handling.
Avatar of Mark Wills
Mark WillsFlag of Australia imageTopic Advisor
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answers