Solved

regular expression in sql server

Posted on 2015-02-23
5
80 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 49

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 143

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 143

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 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