SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Openrowset function unable to read last column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vishal_sql
Posting Yak Master

101 Posts

Posted - 01/14/2013 :  00:59:13  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 01/14/2013 :  03:23:35  Show Profile  Reply with Quote
can you show your OPENROWSET statement used?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vishal_sql
Posting Yak Master

101 Posts

Posted - 01/14/2013 :  04:10:15  Show Profile  Reply with Quote
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\'+@filename

EXECUTE ('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

Edited by - Vishal_sql on 01/14/2013 04:12:30
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/14/2013 :  04:12:24  Show Profile  Reply with Quote
try with IMEX =1

EXECUTE ('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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vishal_sql
Posting Yak Master

101 Posts

Posted - 01/14/2013 :  04:37:32  Show Profile  Reply with Quote
Thats great.
Now the Openrowset is working for column with NULL value.

Thanks Visakh.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/14/2013 :  04:43:20  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000