Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2010-10-25 : 14:51:52
|
| Hi i want to insert a CSV file into a table on the databaseSELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=\\fileserver1\Repository\SNF\FY 2011\HIPPS\;Extensions=CSV;','SELECT * FROM HIPPSFY2011.csv')the above openrowset works fine so i tried the following.USE BRSDATAGOINSERT INTO HIPPSSELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=\\fileserver1\Repository\SNF\FY 2011\HIPPS\;Extensions=CSV;','SELECT * FROM HIPPSFY2011.csv')but i t gives me an errorMsg 295, Level 16, State 3, Line 1Syntax error converting character string to smalldatetime data type.this is the structure of the table CREATE TABLE [dbo].[HIPPS]( [HIPPS] [char](5) NOT NULL, [HIPPS_FROM] [smalldatetime] NOT NULL, [HIPPS_THRU] [smalldatetime] NULL, [HIPPS_PROV] [char](3) NULL, [HIPPS_DESCRIPTION] [varchar](800) NULL, CONSTRAINT [PK_HIPPS_] PRIMARY KEY CLUSTERED ( [HIPPS] ASC, [HIPPS_FROM] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY]the HIPPS_FROM and HIPPS_THRU column in CSV are of date typeANy helpthanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2010-10-25 : 17:10:03
|
| Thanks Tara. I have Null values for HIPPS_THRU. So would SQL Server not let me insert the data from the CSV file?Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2010-10-26 : 10:14:03
|
| in the CSV file, the HIPPS_THRU column is shortdate type and when the cell does not have a date it should import as a NULL into the table. I filled the empty cells with a date and it seems to import now but if it is a empty cell, i think thats where it gives me an error..database - sql server 2000client (my desktop) - sql server 2008.CSV - Office 2010thanks |
 |
|
|
|
|
|
|
|