dbTalk Databases Forums  

Import Excel file to SQL Server

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Import Excel file to SQL Server in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mike
 
Posts: n/a

Default Import Excel file to SQL Server - 12-16-2003 , 10:01 AM






Hi, When I import an Excel file using the DTS Wizard all
text columns are automatically set to the 'nvarchar'
datatype, is there are any way to change that to 'varchar'
without going through every column(have the DTS Wizard set
all text columns to 'varchar', is what I want)?
Thanks!

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: Import Excel file to SQL Server - 12-16-2003 , 10:28 AM






In article <0be701c3c3ed$ef481550$a401280a (AT) phx (DOT) gbl>, mike <mb (AT) mbltd (DOT) com>
writes
Quote:
Hi, When I import an Excel file using the DTS Wizard all
text columns are automatically set to the 'nvarchar'
datatype, is there are any way to change that to 'varchar'
without going through every column(have the DTS Wizard set
all text columns to 'varchar', is what I want)?
Thanks!
There is no way to override this default behaviour of the Wizard. You
could just create the table beforehand. If you don't know what to
create, try building the package by hand. You will click the New button
which pops up a dialog with the suggested CREATE TABLE statement. You
can do some a bit of copy and paste, find and replace, on this code
which should be a quicker way of fixing the types.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #3  
Old   
mike
 
Posts: n/a

Default Re: Import Excel file to SQL Server - 12-16-2003 , 04:21 PM



Thanks for the reply Darren, this will not work for me
since the excel files will have different columns and data
all the time. I've tried creating DTS packages
dynamically using COM but was not very successful, just
could not get it to work. I am now looking at distibuting
SQL-NS dll's and let the user import with the DTS wizard.
I know this is far from a good solution but I'm stumped.
If you have any ideas or some good examples for creating
dynamic DTS packages I would be very greatful. Thanks!

P.S. nvarchar to varchar is an implicit conversion right?
If my SQL stmnts are for varchar will they still work?

Quote:
-----Original Message-----
In article <0be701c3c3ed$ef481550$a401280a (AT) phx (DOT) gbl>, mike
mb (AT) mbltd (DOT) com
writes
Hi, When I import an Excel file using the DTS Wizard all
text columns are automatically set to the 'nvarchar'
datatype, is there are any way to change that
to 'varchar'
without going through every column(have the DTS Wizard
set
all text columns to 'varchar', is what I want)?
Thanks!

There is no way to override this default behaviour of the
Wizard. You
could just create the table beforehand. If you don't know
what to
create, try building the package by hand. You will click
the New button
which pops up a dialog with the suggested CREATE TABLE
statement. You
can do some a bit of copy and paste, find and replace, on
this code
which should be a quicker way of fixing the types.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server
professionals
http://www.sqlpass.org

.


Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: Import Excel file to SQL Server - 12-17-2003 , 01:46 PM



In article <040901c3c422$fad9b650$a301280a (AT) phx (DOT) gbl>, mike <mb (AT) mbltd (DOT) com>
writes
Quote:
Thanks for the reply Darren, this will not work for me
since the excel files will have different columns and data
all the time. I've tried creating DTS packages
dynamically using COM but was not very successful, just
could not get it to work.
To get a start try creating a package as normal and then use the Save As
Visual Basic option to generate some sample code. This should give you a
nice working package. If you wanted to take this further you would need
to write some code to determine the structure of the input file and then
generate the transformations and destination CREATE TABLE statement.
Since this is Excel I assume you can query the Jet provider for the
required meta-data, but it is not something I have ever tried.

Quote:
I am now looking at distibuting
SQL-NS dll's and let the user import with the DTS wizard.
An alternative is to call dtswiz.exe. Not sure on the redistribution
rights of this component, but I assume it is the same as SQL-NS which is
not free. Have a look in Books Online and also the redist.txt file found
on the root of the install media. Simplest option would be to licence as
normal and install EM, but only use what you require, either via your
own SQL-NS code wrapper or DTSWiz.


Quote:
P.S. nvarchar to varchar is an implicit conversion right?
If my SQL stmnts are for varchar will they still work?

Yep.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #5  
Old   
mike
 
Posts: n/a

Default Re: Import Excel file to SQL Server - 12-18-2003 , 11:46 AM



I have succesfully tested distributing/registering the
dll's required to run dtswiz.exe /i (import only) so will
probably go with this solution(just wish DTSWiz would set
excel text columns to varchar rather than nvarchar, but I
could probably just Alter Column datatypes after import if
I really need to). I don't think it's worth the coding
effort to create dynamic dts packages since i can't
reuse/rarely reuse them anyway(excel import files will
always be different), would you agree with this
logic/would you use it? Do you think it's a bad idea to
expose the dts wizard to the user?
Thanks for the input Darren!

Quote:
-----Original Message-----
In article <040901c3c422$fad9b650$a301280a (AT) phx (DOT) gbl>, mike
mb (AT) mbltd (DOT) com
writes
Thanks for the reply Darren, this will not work for me
since the excel files will have different columns and
data
all the time. I've tried creating DTS packages
dynamically using COM but was not very successful, just
could not get it to work.

To get a start try creating a package as normal and then
use the Save As
Visual Basic option to generate some sample code. This
should give you a
nice working package. If you wanted to take this further
you would need
to write some code to determine the structure of the
input file and then
generate the transformations and destination CREATE TABLE
statement.
Since this is Excel I assume you can query the Jet
provider for the
required meta-data, but it is not something I have ever
tried.

I am now looking at distibuting
SQL-NS dll's and let the user import with the DTS wizard.
An alternative is to call dtswiz.exe. Not sure on the
redistribution
rights of this component, but I assume it is the same as
SQL-NS which is
not free. Have a look in Books Online and also the
redist.txt file found
on the root of the install media. Simplest option would
be to licence as
normal and install EM, but only use what you require,
either via your
own SQL-NS code wrapper or DTSWiz.



P.S. nvarchar to varchar is an implicit conversion right?
If my SQL stmnts are for varchar will they still work?

Yep.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server
professionals
http://www.sqlpass.org



Reply With Quote
  #6  
Old   
Darren Green
 
Posts: n/a

Default Re: Import Excel file to SQL Server - 12-19-2003 , 12:51 PM



In article <008c01c3c58e$d8ab51c0$a401280a (AT) phx (DOT) gbl>, mike <mb (AT) mbltd (DOT) com>
writes
Quote:
I have succesfully tested distributing/registering the
dll's required to run dtswiz.exe /i (import only) so will
probably go with this solution(just wish DTSWiz would set
excel text columns to varchar rather than nvarchar, but I
could probably just Alter Column datatypes after import if
I really need to). I don't think it's worth the coding
effort to create dynamic dts packages since i can't
reuse/rarely reuse them anyway(excel import files will
always be different), would you agree with this
logic/would you use it? Do you think it's a bad idea to
expose the dts wizard to the user?
Thanks for the input Darren!

I agree, building your own wizard is hard work, and if the effort is not
justified I see no problem with letting users loose with the wizard. It
is easy enough to use and at the end of the day you can control their
permissions in a the Sql Server level so they can only import into the
Db you allow etc.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.