Reply to Re: SQL Datatypes

Your name:

Reply:


Posted by Erland Sommarskog on 04/01/07 15:20

pinney.colton@gmail.com (pinney.colton@gmail.com) writes:
> I see the approach you're taking. I should have been more clear in my
> original post - it's not just bool's that I have issues with - it's
> every data type. Data that should be stored as an int (or tinyint) is
> stored as a varchar, data that should be stored as a datetime is
> stored as a varchar, data that should be stored as a float is stored
> as a varchar. I'm looking to convert all of that data. Bool data was
> just an example.

The exact validation is different depending on data type. Important is
the use of the CASE expression:

SELECT CASE isdate(varcharcol) THEN convert(datetime, varcharcol) END
FROM tbl
WHERE isdate(varcharcol) = 1

If you don't have the CASE, you can still get a conversion error despite
the filter in the WHERE clause.

Dates are particularly nasty to deal with. If a column says 01/02/03,
what this mean? Feb 1st, 2003, 2nd Jan 2003, March 2nd 2001 or something
else?



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация