Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Field Max Length Issues Importing Flat File

Posted on 2014-07-28
4
Medium Priority
?
273 Views
Last Modified: 2016-02-11
Hello,

I'm importing a .csv file into SQL Server 2008.  I did a "staging" import setting all fields to varchar(255) to see what data they contained.  Next I ran an SSIS Data Profiling Task (thanks Barry) and got the Column Length Distribution profile.  

The max length on most of the date fields is 21 (as expected because the data has double-quote text qualifiers around all of the values); however, some of the date fields have a max length greater than 21.  

When I look for records where the maximum length exceeds 21 I get results but I don't see what I would expect in the actual data (additional characters).

For instance, if I run this:
select top 100 * from MyTable where len(rtrim(ltrim(MY_DATE1)))='28'

Open in new window


I get results like:
"1986-09-14 00:00:00"

which looks like 21 characters to me.  

I think I'm missing some foundational concept here.  :)  

Can anyone help me out?  

TIA!
0
Comment
Question by:ttist25
  • 2
3 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 2000 total points
ID: 40225011
<wild guess + shameless plug>

There are likely characters that are not visible there. I'd download a trial of Ultra Edit, which is one of the many super-dooper text editors on the market.   Then open a file in UltraEdit, copy-paste these values in it, and hit Ctrl-H to go into Hex mode and eyeball the hex value of these characters.

Invaluable when dealing with the output of mainframes that will include characters other than what you intend.

Good luck.
0
 
LVL 1

Accepted Solution

by:
ttist25 earned 0 total points
ID: 40225201
Thanks as always Jim.  

I did what you recommended and saw nothing unusual in the hex values.  This caused me to look more closely at what I was doing and I realized the date value I was looking at was for another (very similarly named) date field.  

DOH.  Smack.  

I'm awarding points for pointing me to a new tool which I'm sure I will use in the future.

Thanks!
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40225303
Better you discover it with us then with your co-workers.  Good luck.  -Jim
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

772 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