Quickly import EXCEL data to tempdb table and script out field descriptor

USE tempdb
GO

SELECT *
INTO MyEXCELSheet
FROM OPENDATASOURCE(
    
'Microsoft.Jet.OLEDB.4.0',
    
'Data Source="E:\atest.xls";Extended properties=Excel 5.0'
)...Sheet1$

--
-- Use Query Analyzer to script out the table in tempdb.
--

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MyEXCELSheet]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[MyEXCELSheet]
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MyEXCELSheet]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE
[dbo].[MyEXCELSheet] (
    
[CustomerID] [nvarchar] (255) NULL ,
    
[EmployeeID] [float] NULL ,
    
[Freight] [float] NULL ,
    
[OrderDate] [datetime] NULL ,
    
[OrderID] [float] NULL ,
    
[RequiredDate] [datetime] NULL ,
    
[ShipAddress] [nvarchar] (255) NULL ,
    
[ShipCity] [nvarchar] (255) NULL ,
    
[ShipCountry] [nvarchar] (255) NULL ,
    
[ShipName] [nvarchar] (255) NULL ,
    
[ShippedDate] [datetime] NULL ,
    
[ShipPostalCode] [float] NULL ,
    
[ShipRegion] [nvarchar] (255) NULL ,
    
[ShipVia] [float] NULL
)
ON [PRIMARY]
END

GO

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MyEXCELSheet]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[MyEXCELSheet]
GO

Comments are closed.

Post Navigation