Solved

regular expression in sql server

Posted on 2015-02-23
5
67 Views
Last Modified: 2015-03-05
Ok, how can I write a regular expression which can tell me a particular row data is not correct date, out of a column , in a table with millions of records

column 1
01-Jan-15
01-Jan-15
01-Jan-15
01-Jan-15
01/Jan/15

what regular expression will return me row no. 5 from above table.
0
Comment
Question by:BeyondBGCM
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40627492
what version of SQL Server is it?

At SQL 2012 TRY_CAST() is available.

select
*
from table1
where try_cast(column1 as date) IS NULL

but the problem with this is performance my be poor on a large table (but the same is likely to be true with alternatives).
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40627543
I confirm that sql server as such does not have have regular expressions.
eventually you don't need such thing, maybe this would be enough already:

where not like '[0-9][0-9]-[JFMASOND][AEPUCO][NBRYLGPVTC]-[0-9][0-9]'
0
 

Author Comment

by:BeyondBGCM
ID: 40628409
but, we can use regular expressions in .net since 1.1 release
0
 

Author Comment

by:BeyondBGCM
ID: 40628463
ie from 2003
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40629996
yes, in .Net, but not in sql server directly
using .net means you would have to bring all the relevant table data from the server to the .net app
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now