| | |
Get data out of excel file stored as an image
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
Ok. One more thing (and I use this technique a lot). You can conditionally inject a zero to your string data based on conditions.
This code will inject a '0' in front of any single digit number.
SQL Syntax (Toggle Plain Text)
CASE WHEN ((cast(f1 as INT) > -10) OR (cast(f1 as INT) < 10)) THEN '0' + f1 ELSE f1 END
This code will inject a '0' in front of any single digit number.
-Mike
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Solved Threads: 1
i am changing the excel column to varchar before i actually write to the sql table.
i used this earlier:
INSERT INTO table(c1,c2)
SELECT Code1,Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$
I modified the above as follows and i think i see correct results:
INSERT INTO table(c1,c2)
SELECT CAST(Code1 AS varchar(6)),Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$
i have to do vast testing before i can say that this worked.
i used this earlier:
INSERT INTO table(c1,c2)
SELECT Code1,Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$
I modified the above as follows and i think i see correct results:
INSERT INTO table(c1,c2)
SELECT CAST(Code1 AS varchar(6)),Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$
i have to do vast testing before i can say that this worked.
Be careful in situations where you have different data types in the same column.
For example, in my spreadsheet, the first four rows contain information that really has nothing to do with the data. The real data starts from the fifth row and down. So in my example, I have integer data in the first column (starting from the fifth row). However, cell A1 contains a title that is a string. If I use
In your case, you're casting to a varchar so no big deal, but if you are casting to a numeric data type you'll need to be aware of the pit falls.
Bottom line - lots of error checking and data massaging may be required.
For example, in my spreadsheet, the first four rows contain information that really has nothing to do with the data. The real data starts from the fifth row and down. So in my example, I have integer data in the first column (starting from the fifth row). However, cell A1 contains a title that is a string. If I use
cast(f1 as int) in my code, it will fail on cell A1.In your case, you're casting to a varchar so no big deal, but if you are casting to a numeric data type you'll need to be aware of the pit falls.
Bottom line - lots of error checking and data massaging may be required.
-Mike
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Solved Threads: 1
Higa, you are right. But in my case, the excel sheet will have only two columns and I know for sure it doesnt cause any problems.
Now I have a new problem. Its about sheet names in the excel. I dont have the problem and solution clearly yet. I will post both of them soon.
OK..here it is. I am trying to read a specific sheet from an excel file. I realized that the name of the sheet may not be same all the time, but the position of the sheet is fixed. I can take the sheet name as input, but sometimes it may have spaces in that name and i tried in vain to read those sheets with spaces. So, two ways..one is to be able to access the sheets by their postion or to be able to read the sheet names with spaces.
If anyone know how to tackle this problem, please post a solution.
Now I have a new problem. Its about sheet names in the excel. I dont have the problem and solution clearly yet. I will post both of them soon.
OK..here it is. I am trying to read a specific sheet from an excel file. I realized that the name of the sheet may not be same all the time, but the position of the sheet is fixed. I can take the sheet name as input, but sometimes it may have spaces in that name and i tried in vain to read those sheets with spaces. So, two ways..one is to be able to access the sheets by their postion or to be able to read the sheet names with spaces.
If anyone know how to tackle this problem, please post a solution.
Last edited by tatini; Nov 2nd, 2007 at 7:27 pm.
![]() |
Similar Threads
- Manipulate Excel file using C++?? (C++)
- Getting A Data From Ms Eccess And Putting It In An Existing Excel File Using Vb 6.0 (Visual Basic 4 / 5 / 6)
- getting data from a text file and putting it in an excel file using visual basic 6.0 (Visual Basic 4 / 5 / 6)
Other Threads in the MS SQL Forum
- Previous Thread: Odd issue with LIKE operator
- Next Thread: Identity column
| Thread Tools | Search this Thread |





