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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Kindly help...

Author  Topic 

tskmjk
Starting Member

11 Posts

Posted - 2010-01-19 : 06:21:50
I have a new requirement where I need to filter out results by checking whether a column has "-" or not. Following will be the dummy data:

Sno Sname Date
--------------------
1 tsk 2009-12-20
2 mjk 4889.6

I need to write a SQL query to filter out the columns which are not in the date format. So I thought that can we do a substring of the column "date" to check whether "-" is present or not. But I am unable to do in SQL SERVER 2005. Kindly help me in this regard.

Regards,

T.Suresh Kumar

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-01-19 : 06:30:56
SELECT *, CASE WHEN [Date] LIKE '%-%' THEN 1 ELSE 0 END
FROM Table1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-19 : 06:31:01
This??

WHERE [Date] NOT LIKE '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-19 : 06:33:29
the data type for Date is string ? Why don't you just use datetime ?


select *
from yourtable
where Date like '%-%'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tskmjk
Starting Member

11 Posts

Posted - 2010-01-19 : 07:10:24
Thanks for your speedy responses guys
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-19 : 08:07:38
"Why don't you just use datetime ?"

Won't hold 4889.6 ... well, it will if that is meant to represent "1913-05-22 14:24"
Go to Top of Page
   

- Advertisement -