Solved

SQL to Excel Dates

Posted on 2013-11-15
5
296 Views
Last Modified: 2013-11-25
I am importing dates from MSSQL 2008 R@ to Excel 2013

The dates come in as text and I have to do the "Text to Columns" every time I import.

Is there a way to make them come in as dates so I do not have to convert them every time??
0
Comment
Question by:HDM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 39652109
If you used Get External Data from the Data ribbon then your import should retain data-types.  In your SQL database-table, are the date-fields defined as datetime or varchar?  If they are defined as varchar then you could CAST into datetime by altering the SQL generated by Excel.
0
 

Author Comment

by:HDM
ID: 39660199
they are defined as date.

I could change these simply if there is a better format.
0
 

Author Comment

by:HDM
ID: 39660204
I am currently using the tab "From Other Sources" under the "Get External Data" tab.

Under that i use the "From SQL server" option
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39662634
Your import technique is correct and should retain data-type.

My MSSQL 2008 R2 database is using collation-sequence SQL_Latin1_General_CP1_CI_AS (not sure if that makes a difference), build 7600. Unfortunately, I do not have Excel 2013, I'm using Excel 2007.

When I import varchar fields that contain only numbers then Excel views that field as text (which is correct, retains data-type). When I import datetime fields then Excel retains date formats (i.e., the final Excel field is not text).  When I import integer fields then Excel formats the field as a number (which is correct).
0
 

Author Closing Comment

by:HDM
ID: 39675310
Thanks!!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question