Click here to Skip to main content
15,888,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got an Ms excel file want to import to SQL Server 2005. Everyone know how to import Ms Excel data file into SQL Server 2005?I saw some SQL Server 2005 have Import/Export data button.I wonder why my SQL server 2005 do not have.

Thanks in advance.
Posted
Updated 16-Jun-13 23:56pm
Comments
Samresh.ss 17-Jun-13 6:44am    
You can refer the methods to import here
http://msdn.microsoft.com/en-us/library/ms140052.aspx
Adrian4263 17-Jun-13 22:13pm    
I've tried already,even there got 5 method,but I cannot finish the steps,because in my SQL server I cannot find the import/export data button,SSIS package..
Herman<T>.Instance 17-Jun-13 8:10am    
do you use Sql Server Management studio?
Adrian4263 17-Jun-13 22:08pm    
Mine one is SQL Server Management Studio Express.Is it same or different?
Herman<T>.Instance 18-Jun-13 15:43pm    
good enough

In MS Excel, "Save" spreadsheet as tab-delimited text. This is the best way to deal with XL, imho ... and here's an example of such output; te conntent of "cpqa_AF_xlsDataTDIdea(td).txt"
Zany, Assignment	quisling.tito.com	yes	2013-02-04 11:38:01.760
Captain, Theodorus	mike.twentysixteen.com	yes	2012-12-14 11:59:02.110
Wynn, Cruikshank	ss.nautpott.com	no	2011-07-26 07:52:15.007

The TSQL ...
USE [cpqa]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[cpqa].[tbl_AF_xlsDataTDIdea]') AND type in (N'U'))
DROP TABLE [cpqa].[tbl_AF_xlsDataTDIdea]
GO

CREATE TABLE [cpqaAnswers].[cpqa].[tbl_AF_xlsDataTDIdea](
	[name][nvarchar](73),
		[email][nvarchar](42),
			[fmUser][nvarchar](5),
				[sIn][datetime]
				)

BULK INSERT [cpqaAnswers].[cpqa].[tbl_AF_xlsDataTDIdea] FROM 'C:\cpqa_AF\cpqa_AF_xlsDataTDIdea(td)'	

SELECT [name]
		,[email]
			,[fmUser]
				,[sIn]
  FROM [cpqaAnswers].[cpqa].[tbl_AF_xlsDataTDIdea] 
GO

This take on Excel input is strictly tab-delimited-required. If the tab-delimited file is not data separated by single tab there will be errors at the BULK INSERT stage, guaranteed.
 
Share this answer
 
Comments
Adrian4263 17-Jun-13 23:00pm    
Can you explain in clearly to me?I am not so understand the code that you wrote."Cpqa" is the file name right? Then what is "tbl_AF_xlsDataTDIdea"? and "cpqaAnswers"? Lets say, my file name is "excel" my table name is "excel1",then how I amend it?
RedDk 18-Jun-13 12:32pm    
Sure,1. "[cpqaAnswers]" is the name of the database.

2. "[cpqa]" is the name of the schema.

3. "cpqa_AF_xlsDataTDIdea(td)" is the name of the saved .txt file

Just replace in 1. ... well I don't know the name of your database ...

Replace in 2. [cpqa] with [dbo] ... don't know your schema name either; just guessing here ...

Replace in 3. cpqa_AF_xlsDataTDIdea(td).txt with excel.txt.

You say your table is named excel1? Then replace tbl_AF_xlsDataTDIdea with excel1.
Adrian4263 18-Jun-13 21:40pm    
Thanks a lot,I think it is helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900