Importare dati da Excel a SQL Server 2005 Express

lunedì, 5 maggio 2008 09.55 by Marco Bellinaso

Quando l'altro giorno mi è stato chiesto di importare i dati di un foglio Excel in una tabella di SQL Server 2005, mi son detto "no problem, lancio il Data Import/Export wizard, e via". Purtroppo tale tool non è presente nella versione Express, dal momento che mancano anche i SQL Server Integration Services (SSIS) and SQL Server Agent sui quali quel wizard si basa. Mi sembrava uno spreco installare la versione Standard solo per questo, quindi ho cercato qualche soluzione alternativa. E' possibile ad esempio scrivere una macro VBA direttamente in Excel per ciclare sulle righe e colonne, e inserire i dati in SQL Server tramite il vecchio Recordset di ADO...ma anche questo mi sembrava troppo lavoro per un compito così semplice! La soluzione che ho adottato -- e che ha funzionato alla perfezione -- è stata di usare la funzione OPENROWSET, in questo modo:

SELECT * INTO Negozi FROM 
OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\temp\DatiNegozi.xls', [Sheet1$])

Questo codice prende tutti i dati presenti nel file XLS specificato (nel foglio Sheet1), e li copia in una nuova tabella chiamata Negozi. La prima riga del foglio Excel dovrebbe essere di intestazione, ed è quella che il comando utilizzerà per estrarre i nomi dei campi da creare nella nuova tabella. Se alcuni campi dovessero essere creati con un tipo diverso da quello desiderato (ad esempio float ancihè int, o varchar invece di nvarchar) sarà ovviamente possibile modificare lo schema della tabella direttamente da Management Studio Express dopo l'importazione.

Il comando però non funzionerà se le "Ad Hoc Distributed Queries" non sono abilitate. Per attivarle, eseguire i seguenti statement: 

sp_configure 'show advanced options',1
reconfigure with override
go
sp_configure 'Ad Hoc Distributed Queries',1
reconfigure with override
go 

Correntemente valutato 5.0 da 4 utenti

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Segnala:  
Tags:   , , , , ,
Categorie:   Sviluppo software
Azioni:   E-mail | Permalink | Commenti (49) | RSS CommentiRSS comment feed

Post correlati

Commenti

maggio 8. 2008 12.16

Alessandro

Siccome uso solo la versione Express questa dritta è utile ed interessante per me, e credo per molti altri.
Ho 2 domande da porti a vari propositi:
1) sai consigliarmi qualche testo, tutorial ecc. chiaro e completo su SqL Server 2005 (standard - express)?. Ho lacune da colmare ( prima o poi )
2) ci sarà un seguito a TheBeerHouse in c# 3.0 e NET 3.5?
grazie, e baci alla "bestia" da parte di Minnie (la mia)

Alessandro

maggio 8. 2008 16.16

Marco Bellinaso

Ciao Alessandro,

1) dipende da che area di SQL Server vuoi approfondire Smile TSQL? CLR Integration? Amministrazione? DB Design? Tuning? Ci sono libri dedicati per ciascuno di questi argomenti. Io di solito per scegliere un libro vado su Amazon, faccio una ricerca e vedo quali sono testi con il più alto numero di ottime recensioni Smile Non sarà un metodo infallibile, ma finora ha dato buoni risultati Smile

2) Ci dovrebbe essere, ma non si sa ancora la data...

P.S: Mescal ringrazia...e aspetta di vedere anche Minnie su Pet-files ;)

Marco Bellinaso

maggio 27. 2008 12.34

wiplock

ero interessato a importare in una tabella (non ancora esistente) il contenuto di un file excel ...

ma eseguendo

select *
into [XXXXX].[dbo].[Compleanni]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel8.0;Database=C:\Users\................\Desktop\COMPLEANNI.xls;HDR=YES', 'SELECT * FROM [Sheet1$]')

ho questo errore:

Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".


dove [XXXXX].[dbo].[Compleanni] è una tabella che non esiste... e vorrei che mi venisse creata
e C:\Users\................\Desktop\COMPLEANNI.xls è il path assoluto del file


devo fare qualcosa sui linked server ?? o configurare qualcosa per 'Microsoft.Jet.OLEDB.4.0' ??


grazie Tong

wiplock

maggio 27. 2008 12.53

wiplock

nb.
mi sono scordato di sottolineare il fatto che il file excel è sul mio desktop ...
mentre il db su cui devo scrivere è su un altra macchian a cui sono collegato con sqlserver management

wiplock

giugno 9. 2008 11.45

massimo

ciao, ho provato ad usare l'openrowset come dici letto nell'articolo ma mi da un errore del genere, hai idea di cosa può essere?

Il provider OLE DB "Microsoft.Jet.OLEDB.4.0" per il server collegato "(null)" ha restituito il messaggio "Impossibile trovare ISAM installabile.".
Messaggio 7303, livello 16, stato 1, riga 1
Impossibile inizializzare l'oggetto origine dei dati del provider OLE DB "Microsoft.Jet.OLEDB.4.0" per il server collegato "(null)".


ciao
grazie

massimo

dicembre 16. 2008 02.50

Busby SEO Test

Wanna say thank you for all the information on site site. Thanks

Busby SEO Test

gennaio 12. 2009 15.35

Massimiliano

Grazie mille, ha funzionato tutto a perfezione (SQL Server 2005 Express da cartella Excel formato 2003, su pc con Vista e Office 2007.... ci speravo poco e invece... mai dire mai)
Smile

Massimiliano

dicembre 6. 2009 03.46

faxless payday loans

Your blog is so informative … keep up the good work!!!!

faxless payday loans

dicembre 28. 2009 09.29

paydayloans

I just hope to have understood this the way it was meant

paydayloans

dicembre 30. 2009 02.15

Michigan Payday Loans

I like what I see. keep it going

Michigan Payday Loans

gennaio 3. 2010 15.26

quick loans

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well.

quick loans

gennaio 18. 2010 08.29

printing bellevue washington

Police begin campaign to run down jaywalkers

Safety Experts say school bus passengers should be belted

Drunk gets nine months in violin case

Juvenile court to try shooting defendant

Killer sentenced to die for second time in 10 years

Drunken drivers paid $1000 in '84

Stolen Painting Found By Tree

Judge To Rule On Nude Beach

Police Discover Crack In Australia

Men Recommend More Clubs For Wives

Two Convicts Evade Noose; Jury Hung

Deaf mute gets new hearing in killing


Regards
Lop








printing bellevue washington

gennaio 21. 2010 10.42

Cheap International Calls

One day an Englishman, a Scotsman, and an Irishman walked into a pub together. They each bought a pint of Guinness. Just as they were about to enjoy their creamy beverage, three flies landed in each of their pints, and were stuck in the thick head. The Englishman pushed his beer away in disgust. The Scotsman fished the fly out of his beer, and continued drinking it, as if nothing had happened. The Irishman, too, picked the fly out of his drink, held it out over the beer, and started yelling, "SPIT IT OUT, SPIT IT OUT, SPIT IT OUT!!!!"



Regards and respect
Burnett









Cheap International Calls

febbraio 13. 2010 11.08

teeth whitening reviews

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

teeth whitening reviews

febbraio 16. 2010 14.57

Herbal colon cleanse

There are certainly a lot of details like that to take into consideration.

Herbal colon cleanse

febbraio 22. 2010 11.59

Acne products

Interesting article. Were did you got all the information from? Anyway thank you for this great post!

Acne products

febbraio 27. 2010 19.42

cash advance

Resources like the one you mentioned here will be very useful to me! I will post a link to this page on my blog. I am sure my visitors will find that very useful.

cash advance

marzo 6. 2010 16.22

no credit check loans

Hi Webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do! Big thanks for the useful info i found on Importare dati da Excel a SQL Server 2005 Express.

no credit check loans

marzo 9. 2010 10.49

replica watches

thanks for the share

replica watches

marzo 10. 2010 11.22

payday cash loans

Me and my friend were arguing about an issue similar to this! Now I know that I was right. lol! Thanks for the information you post. Big thanks for the useful info i found on Importare dati da Excel a SQL Server 2005 Express.

payday cash loans

marzo 15. 2010 13.14

Stretch marks treatment

In searching for sites related to web hosting and specifically comparison hosting linux plan web, your site came up.You are a very smart person!

Stretch marks treatment

marzo 18. 2010 08.41

registry fix review

Thanks for sharing.

registry fix review

marzo 19. 2010 10.31

rolex replica

thank you very much for sharing this article!

rolex replica

marzo 22. 2010 15.06

ssk sorgulama

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

ssk sorgulama

marzo 22. 2010 22.19

treatment for toenail fungus

I just hope to have understood this the way it was meant

treatment for toenail fungus

marzo 23. 2010 16.21

ehliyet

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

ehliyet

marzo 24. 2010 14.43

rolex replica

thank you

rolex replica

marzo 24. 2010 16.41

credit card debt help

Hi. I read a few of your other posts and i wanted to say thank you for the informative posts.

credit card debt help

marzo 25. 2010 14.07

Gout Natural Treatment

Hi, your website is the best anti-tode for all those doomsday prophets in existence. I can see that you simply take a great deal of time in crafting up everything nicely. Many thanks for maintaining such a nice site.

Gout Natural Treatment

marzo 25. 2010 14.56

bağkur

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

bağkur

marzo 27. 2010 10.15

cheap dental insurance

Excellent post. Bookmarked it already. have a nice day, mate.

cheap dental insurance

marzo 29. 2010 12.26

Reverse Phone Lookup

Nice information. Its usefulness and significance is overwhelming. Wonderful post

Reverse Phone Lookup

marzo 29. 2010 21.36

arac sorgulama

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

arac sorgulama

marzo 30. 2010 03.23

Unusual Engagement Rings

Noo! I'm using my iphone and I cannot look to become able to open the page appropriate. I am going to be back again to go through this tonight when I get back from school. The topic looks like one thing I need to go through. I've bookmarked it and I'll be back again later.

Unusual Engagement Rings

marzo 30. 2010 05.58

Inkjet Ink Cartridges

Hi, has anybody learned the solution towards problem of RSS feeds? Is there an simple solution to this issue?Can I do something to determine the feeds easily, or do I have to discover a different feed reader?

Inkjet Ink Cartridges

marzo 30. 2010 14.02

dirt cheap rims

You will find definitely a great deal of information like that to take into consideration. That is certainly a excellent stage to bring up. I present the thoughts above as general inspiration but clearly you can find questions like the a single you bring up in which the most critical problem are going to be functioning in honest very good faith.

dirt cheap rims

marzo 31. 2010 01.35

Emerald Cut Engagement Rings

Hi there, Im at my work and was browsing about the internet, goofing off, when I came throughout your web site. It's fairly nicely executed, and I surely like your mode of writing.

Emerald Cut Engagement Rings

marzo 31. 2010 04.27

Cheap Ink Cartridges

It is a exceptional post, I located your weblog site checking aol for a comparable topic and arrived to this. I couldnt come over to significantly other particulars on this piece of content, so it had been excellent to learn this a single. I certainly is going to be again to look at some other posts that you just have an additional time.

Cheap Ink Cartridges

aprile 3. 2010 11.40

genital wart treatment

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. Big thanks for the useful info i found on Importare dati da Excel a SQL Server 2005 Express.

genital wart treatment

aprile 4. 2010 16.54

auto financing for bad credit

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

auto financing for bad credit

aprile 8. 2010 16.14

gerdek gecesi

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

gerdek gecesi

aprile 10. 2010 03.21

six pack abs

Many thanks for taking the time to discuss this, I really feel strongly about it and adore reading a lot more on this topic. If possible, as you gain understanding, would you mind updating your website with extra facts? It can be very very helpful for me.

six pack abs

aprile 10. 2010 17.10

digestit

The greatest glory in living lies not in never falling, but in rising every time we fall.

digestit

aprile 11. 2010 05.27

how to get six pack abs

I have been reading your posts frequently. I need to say that you just are performing a good job. Please retain up the excellent perform.

how to get six pack abs

aprile 11. 2010 05.27

six pack abs exercises

Many thanks for taking the time to discuss this, I really feel strongly about it and adore reading a lot more on this topic. If possible, as you gain understanding, would you mind updating your website with extra facts? It can be very very helpful for me.

six pack abs exercises

aprile 12. 2010 04.05

cheap dental insurance

I would like to thank you for your efforts you could have produced in writing this post. I'm hoping the same ideal operate from you within the upcoming as well. In fact your creative composing abilities has inspired me to begin my very own BlogEngine blog now. Truly the blogging is spreading its wings rapidly. Your create up is really a good example of it.

cheap dental insurance

aprile 12. 2010 07.53

how to repair your credit

Couldnt be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I'll forward this article to him. Pretty sure he will have a good understand. Thanks for sharing! Big thanks for your valuable information i determined on Primer post.

how to repair your credit

aprile 12. 2010 07.53

how to improve my credit score fast

Howdy, i understand your weblog occasionally and i very own a related one and i was just wondering if you get a great deal of spam comments? If so how do you prevent it, any plugin or something it is possible to advise? I get so much lately it is driving me mad so any assistance is really a lot appreciated.

how to improve my credit score fast

aprile 13. 2010 20.30

getting rid of cellulite

Couldnt be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing! Big thanks for the useful info i found on Importare dati da Excel a SQL Server 2005 Express.

getting rid of cellulite

Commenti chiusi