1

I have data this is linked from SQL Server into an excel document. The column format on the SQL Server is datetime2.

When I get the data via an ODBC connection it comes across as a string?

I tried using

CAST(column AS DATE ) 

but that didn't work.

I tried reformatting via

CONVERT(VARCHAR(10), column, 103) 

as well but that didn't work.

I tried retrieving the data via Microsoft query as well but that didn't work.

At the moment I am using VBA code like:

While (ActiveCell.Value <> "")
  ActiveCell.Value = DATEVALUE(ActiveCell.Value)
  ActiveCell.Offset(1,0).Activate
Wend

and looping through each column that needs this treatment but 100000 rows in multiple columns takes forever to loop through. Are there any alternatives?

1
  • You might find this post helpful. If you stick with your current method make sure ScreenUpdating=False is set before your loop. Commented Oct 25, 2013 at 4:30

3 Answers 3

2

It appears that Excel and Access as well don't like the SQL Server datetime2 format.

I have converted the data into datetime format and that seems to be working now.

Sign up to request clarification or add additional context in comments.

Comments

1

You can simply convert date in the Excel to the following format:

"YYYY-MM-DD HH:mm:ss"

This is the default ODBC canonical format. In this case the implicit conversion will be made and the correct results will be achieved.

Another way is to try to perform convert using another style:

CONVERT(VARCHAR(10), column, 120)

Comments

0

No MACRO's required, us Excel table columns instead.

Any ODBC connections in Excel returns a Table. Simply add a new column to the right of your table with a calculation. It should look something like this =DATEVALUE([@DateColumnFromODBC])

The column will add and shrink with your table and always retain it's reference as long as the ODBC connection stays the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.