I have a spreadsheet I am trying to Query as follow and it works:
"SELECT [Product ID] FROM Sheet1$"
But for some odd reason productIDs that are only numeric displays as blanks whereas non numeric productIDs do display.
So I tried a different query:
"SELECT CAST([Product ID] AS VARCHAR(25)) FROM Sheet1$"
But I got an error message. How far can I take TSQL to query a spreadsheet?
Yama
--
Regards,
Tom Ogilvy
"Yama" <anon...@discussions.microsoft.com> wrote in message
news:4F63942D-D237-4457...@microsoft.com...
That's the obvious deduction! :-)
How to SELECT every cell in a specific format. In SQL I can either use a CAST or a CONVERT. How about in EXCEL Query language?
Yama
----- Tom Ogilvy wrote: -----
I was able to duplicate this behavior. If the column majority data type is STRING then anything NUMERIC will return as a NULL or as a blank (empty) field.
How can I resolve this?
Yama
----- Yama wrote: -----
I don't think you can force Excel to grab all data without using a
workaround. The ODBC driver scans the first 8 rows of data in each column
to determine the data type. If the data type is determined to be numeric,
then Excel will ignore non-numeric fields (and possibly vice versa).
There are a few workarounds you could try:
1) Add 8 rows of "fake" data to the top of your data set. For example, if
you want to force the column to be text, then you could use "aaa" in each
row. You can hide these rows to avoid confusion.
2) You can tell the ODBC driver that you want to scan more or less rows than
8 (even all rows) in order to determine data type. Although there is a
parameter that is supposed to do this, it doesn't work. Here are a few
relevant articles that discuss the issue and workaround:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257819
http://support.microsoft.com/default.aspx?scid=kb;EN-US;189897
--
Regards,
Jake Marx
MS MVP - Excel
www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]
To work around this problem for read-only data, enable Import Mode by using
the setting "IMEX=1" in the Extended Properties section of the connection
string. This enforces the ImportMixedTypes=Text registry setting. However,
note that updates may give unexpected results in this mode. For additional
information about this setting, click the article number below to view the
article in the Microsoft Knowledge Base:
So maybe you can do something with the IMEX property.
--
Regards,
Tom Ogilvy
"Jake Marx" <msn...@longhead.com> wrote in message
news:Os27HBx%23DH...@tk2msftngp13.phx.gbl...
You both contributed with such dexterity! Thank you very much.
Tom your solution for adding the IMEX=1 worked great (I just want a read-only solution; hence, your input was great):
'--// Using VB.NET and ASP.NET
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\yamabiz.com\ProductCatalog.xls;" & _
"Extended Properties=""Excel 8.0;IMEX=1""" '--// GREAT JOB TOM
Dim da As New OleDbDataAdapter("SELECT [Product ID], [Description], [Date Created], [ISBN] " & _
" FROM [Sheet1$]", strConn)
da.TableMappings.Add("Table", "ProductCatalog")
da.Fill(myDataset)
DataGrid1.DataSource = ds.Tables(0).DefaultView
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim s As String = ds.Tables(0).Rows(i)("Product ID").ToString
Response.Write(s + "<br>")
Next
DataGrid1.DataBind()
End Sub
Thank you very much to both of you guys,
Good catch, Tom - I missed that....
> I don't think you can force Excel to grab all data without using a
> workaround. The ODBC driver scans the first 8 rows of data in each column
> to determine the data type.
The quoted 8 rows is a registry setting:
Hkey_Local_Machine/Software/Microsoft/Jet/4.0/Engines/Excel/TypeGuessRows
Setting the value to 0 (zero) should force ADO to scan all column
values before choosing the appropriate data type.
--
Right - and point #2 in my post and the second KB article referred to this
workaround.