Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


8d52797c436

264 posts

Ultimate Geek
Inactive user


#36907 3-Jul-2009 10:18
Send private message

Hi Peoples,

I'm attempting to import a csv file into a databse table using a stored procedure, but I'm running into a little issue with one of the date fields. The column is in smalldatetime format, and the value of the field that the bulk insert is failing on is "01/06/2008", on the first row of the csv. The error I am getting is a type mis-match error. This is the 10th column in the db so i know its inserting the rest of the data properly.

Any help anyone can give would be much appreciated.

Create new topic
freitasm
BDFL - Memuneh
80646 posts

Uber Geek
+1 received by user: 41030

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

#230616 3-Jul-2009 10:40
Send private message

Have you tried inserting '2008-06-01' instead?





Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 




8d52797c436

264 posts

Ultimate Geek
Inactive user


  #230617 3-Jul-2009 10:42
Send private message

I just tried changing the value in the cvs of the first row and I'm still getting the same error.

8d52797c436

264 posts

Ultimate Geek
Inactive user


  #230625 3-Jul-2009 11:04
Send private message

I just tried changing the format to 20080601 as well with no luck. I did however manage to use DTS to import that data. Does anyone know of a way I can create a stored procedure from this? Or should I just make it a scheduled task? The data will need to be updated every few weeks but I would rather have it as a stored procedure so I can interact with it through the website rather than having to remote console in all the time.



8d52797c436

264 posts

Ultimate Geek
Inactive user


  #230630 3-Jul-2009 11:24
Send private message

Just realised that the data is being imported all as a varchar which is not what I want, and I really wanna try and get the sp working. The sp I am using is

CREATE PROCEDURE dbo.sp_ImportData

AS

BULK

INSERT Data

FROM 'c:\Data.csv'

WITH

(
FIRSTROW=2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

I realise I probably have to convert the data from a varchar to smalldatetime or something similar, just not sure how. (You'll have to forgive me, I'm really really new to all this database stuff).

Thanks for any suggestions or help.

8d52797c436

264 posts

Ultimate Geek
Inactive user


  #230671 3-Jul-2009 13:25
Send private message

Well I have just figured out what the problem was. When I was opening the file the default was for it to open in Excel, which is fine, except that excel displays the information slightly differently to how it appears in the csv. In the csv everything that is not a number is surrounded by " ", with numbers having nothing surrounding them. In excel everything was displayed without quotes. The solution is to create a File Format to import the data into the table.

Hopefully this helps save someone else from this mistake later on.

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.