Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Vishal_sql
Posting Yak Master
102 Posts |
Posted - 2013-01-14 : 00:59:13
|
While using OPENROWSET in SQL Server 2005 for importing, I have 33 columns in excel of which 32 columns are read/imported properly by openrowset function but 33rd column is read as NULL values.It seems that 33rd columns has 1st row as 'NULL' so it considers all rows in 33rd column as 'NULL'But if I put any value in 1st row of 33rd column it reads the appropriate values in 33rd columns.Any suggestions on how to traet this scenario.Note:- 33rd column is last column of my excel data |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-14 : 03:23:35
|
can you show your OPENROWSET statement used?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Vishal_sql
Posting Yak Master
102 Posts |
Posted - 2013-01-14 : 04:10:15
|
This is what I used to read DECLARE @filename NVARCHAR(100)DECLARE @FileLocation NVARCHAR(200)DECLARE @SheetName NVARCHAR(100)SET @SheetName='ResourceDemand'SET @filename= 'Engine_Capacity_SolDelivery_New' SET @FileLocation='H:\E4SE Resource Plan Import\'+@filenameEXECUTE ('SELECT * FROM OPENROWSET ( ''Microsoft.Jet.OLEDB.4.0'', ' + '''Excel 8.0;Database=' + @FileLocation + ';HDR=YES'', ' + '''SELECT * FROM [' + @SheetName + '$A:AB]'') WHERE [Ready To Import]=''y'' OR [Ready To Import]=''Y''' );I have put A:AB as the range of the columns in above query although the columns are dynamic so it could be removed |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-14 : 04:12:24
|
try with IMEX =1EXECUTE ('SELECT * FROM OPENROWSET ( ''Microsoft.Jet.OLEDB.4.0'', ' + '''Excel 8.0;Database=' + @FileLocation + ';HDR=YES;IMEX=1'', '+ '''SELECT * FROM [' + @SheetName + '$A:AB]'') WHERE [Ready To Import]=''y'' OR [Ready To Import]=''Y''' );------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Vishal_sql
Posting Yak Master
102 Posts |
Posted - 2013-01-14 : 04:37:32
|
Thats great.Now the Openrowset is working for column with NULL value.Thanks Visakh. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-14 : 04:43:20
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|