Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 exclude data from query

Author  Topic 

krathbun
Starting Member

2 Posts

Posted - 2014-11-24 : 13:11:02
I have a column that is VARCHAR(30) this column is supposed to contain values that "look" like a date in the form mm/dd/yyyy - however because it is a free-text character field often times data is entered other then a date -- "text" -

How do I return only the data that is in the format of mm/dd/yyyy

MSSQL 2012

Karen Rathbun

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-24 : 13:12:15
You can use the ISDATE function.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

krathbun
Starting Member

2 Posts

Posted - 2014-11-24 : 13:32:23
OK - ISDATE does give me a 1 or 0(if not a date) -- how do I then return the actual data for when the statement is true?

Karen Rathbun
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-24 : 14:13:57
select datetimecolumn fromyourtable where isdate(datetimecolumn) = 1

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -