473,424 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

Problem with excel sheet upload into sqlserver

Hello Everyone,

I need to upload excel sheet in to the database. Which i am doing with the query

Expand|Select|Wrap|Line Numbers
  1.     SELECT * INTO temp FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  2.     'Excel 8.0;Database=C:\Dokumente und Einstellungen\l.varada\Desktop\BA-Control.xls',
  3.         'SELECT * FROM [qry_BA_Controlling (Report)$]')
Here C:\Dokumente und Einstellungen\l.varada\Desktop\BA-Control.xls is the path from where the excel file needs to be fetched.
qry_BA_Controlling (Report) is the name of the worksheet.

So on executing the query, a table with name 'temp' is created. With records that are populated from excel.

Now here i have a date field in excel. sometimes the values of this field are not uploaded properly into the temp table. The values for this date field are set to NULL eventhough they have values in EXCEL.

I have modified my query so,

Expand|Select|Wrap|Line Numbers
  1.     Insert into temp Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
  2.         'Excel 8.0;Database=C:\Dokumente und Einstellungen\l.varada\Desktop\BA-Control.xls',
  3.          HDR=YES', 'SELECT * FROM [qry_BA_Controlling (Report)$]')
Here temp is an existing table, i have defined the date type of the field [creation date] to varchar and uploaded the excel. Then i used **convert** to change the datatype to the correct format..

update temp set [Creation date] = CONVERT (varchar,[Creation date],101)

Even now it is populating NULL values..Or this conversion needs to be done while uploading. if so, please let me know or suggest me an alternative approach..
Jul 13 '10 #1
4 3504
ck9663
2,878 Expert 2GB
Is it NULL before or after you update it?

~~ CK
Jul 13 '10 #2
@ck9663
Once i upload the excel file, the value of this date field is NULL. Even after update the value is NULL itself.
Jul 14 '10 #3
ck9663
2,878 Expert 2GB
How does your date field in excel look like? Is it an actual date? Check the dateformat setting on your sql server.

Good Luck!!!

~~ CK
Jul 14 '10 #4
Jerry Winston
145 Expert 100+
Can you post a sample of what you get back when you run this:

Expand|Select|Wrap|Line Numbers
  1.  Select [Creation date] FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\Dokumente und Einstellungen\l.varada\Desktop\BA-Control.xls',HDR=YES', 'SELECT [Creation date] FROM [qry_BA_Controlling (Report)$]')
The upload is working if you're getting back something like this:
Expand|Select|Wrap|Line Numbers
  1. 2010-05-09 00:00:00.000
  2. 2010-05-10 00:00:00.000
  3. 2010-05-11 00:00:00.000
  4. 2010-05-12 00:00:00.000
  5. 2010-05-13 00:00:00.000
Here's the catch. The data type for the [Creation date] in your temp table is varchar. The length of the varchar field directly affects how much of the date string from the Excel file you can store before the data is truncated. If your [Creation date] field is defined as VARCHAR, you're only keeping the first character of the date string from Excel. Further, the line:
Expand|Select|Wrap|Line Numbers
  1. update temp set [Creation date] = CONVERT (varchar,[Creation date],101)
does not convert datetime to varchar because the [Creation date] field is ALREADY a varchar type. If you want to store a formatted date value in a varchar type field you would need to convert your varchar to a datetime and apply the datetime formatting with something like this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE temp
  2. SET [Creation date] = CONVERT(varchar,convert(datetime,[Creation date]),101)
The size, VARCHAR(20), I chose is completely arbitrary. However, the minimum size required depends on the date format you choose. VARCHAR(20) will work fine with some formats(101,102,104) but will be too short for others (109,113). If Excel date data was stored in a datetime type field in the SQL table, the field length would be consistent and post-import UPDATEing would become irrelevant because the storage format would be consistent as well. you would need to format the [Creation date] field only for your output:
Expand|Select|Wrap|Line Numbers
  1. SELECT convert(varchar,[Creation date],101) FROM [temp]
Jul 21 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rajiv | last post by:
HI ALL, actually , i m working in a company having large number of employee , i have two userid and password . on id is from admin group(id given to me by technology manager) of the server and...
3
by: nicholas | last post by:
What would be the best and easiest way to implement a web page that allows me to: - import an Ms Excel-sheet in a database on a Ms Sql 2000 Server - this should be done through an asp.net...
0
by: KK | last post by:
Hi, I am using Response object in vb.net to download an excel sheet with data. It worked well and I could download excel file with data. But suddenly It started downloading only blank excel...
3
by: Kbalz | last post by:
Hello, I'm trying to create an application for a friend's business. He gets Excel Spreadsheets from a lab - he would like for his partners to be able to Upload this Sheet to a website, and have the...
6
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender,...
2
by: thangsan | last post by:
Hi Friends, In my project i need to Export the Data from Sql server to Excel Sheet. It should be auto schedulder certain intervals(months). i want to store the Excel sheet in .CSV ...
0
by: thinkwebs | last post by:
Hi Guys Just i am trying to upload a excel sheet and read the data from excel sheet to database.it work properly while i run it in my program.but while i try to run in virtual folder or in web a...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
8
ammoos
by: ammoos | last post by:
Hi Friends I am getting the following error when I am trying to read data from an excel sheet using sql script OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.