LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Excel date fields to MS SQL Sever via OLE - Solved

Nothing like posting a question to make the answer clear...

My OLE code buids a string that becomes the insert query on the SQL server
side.

The string looks something like:

Insert into tableX(Field1, Field2, Field3) Values ('StringValue',
numericValue)

Two things.
First: I needed to add the date value and time value from Excel into a
single number.
Second: rather than submit the value as a value, I send it as a string ala
Insert into tableX(Field1, Field2) Values ('MyString', '12/31/2008 08:00:00
AM')

poof, works great.

Hope this is of value to others.

Doug

"Doug_F" wrote:

Background:
I have Excel files that are not in a good 'data' format so I'm planning to
migrate the data out of Excel into MS SQL server. Since the data is spread
all over the place in the current Excel files, I'll need to write code to
grab the right data, build a select statement, and push the data into SQL
Server.

Current status:
I have working code that pushes the stuff I want into SQL server. Woot!

Problem:
The excel files contain date and time fields. The date cells have values of
39000, etc and the time fields are decimals from 0 to 1. All pretty standard.

When I grab a date field using the following OLE code:
TestDate = Cdat(xlSheet2.Range("D8").Value)
And then display it back, I see an actual date.
When I do the same thing with a time field, I just see the decimal number.

Problem is that when they get to SQL server,
Dates are all: 1/1/1900 12:00:00 AM
Times a 1/1/1900 with what appears to be the right time.

The SQL server fields are Datetime.

I'm stuck - any suggestions?

TIA.

Doug

ps - I'm going to cross post in the SQL server group.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
read data in an excel file on a remote sever [email protected] Excel Programming 1 December 24th 06 07:34 AM
Excel SHOULD NOT AUTO-CHANGE formated text fields to DATE FIELDS! PSSSD Excel Worksheet Functions 2 August 8th 06 09:31 PM
How to install OLE Sever reneabesmer Setting up and Configuration of Excel 1 September 9th 05 01:11 PM
how to get the number of days between two date formatted fields in vba for excel? Daniel Excel Worksheet Functions 1 July 12th 05 01:53 AM
Problems with Find and Date Fields in Excel macro Nick Marshall Excel Programming 1 October 15th 03 05:01 PM


All times are GMT +1. The time now is 02:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"