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.
| Author |
Topic |
|
laailalalaa
Yak Posting Veteran
57 Posts |
Posted - 2009-11-18 : 07:17:07
|
| i have table A(id, reg_exp). in reg_exp i need to store a regular expression that would contain 5 digits.1. how do i write such a reg expr in sql server?then i do a select based on an input string, that retrieves id when the input string is numeric and has 5 digits. 2. how do i write such a query? one where i would compare a string with a regular expr in t-sql?thanks |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-18 : 07:22:56
|
| Post some sample data with expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-11-18 : 07:24:11
|
You can do that through the LIKE keyword.It isn't a full regular expression engine but if you want to find any string containing at least five numbers you can do this:DECLARE @foo VARCHAR(255)SET @foo = 'asdasd2asda1asfdf5gsdf3asdasd9'IF @foo LIKE '%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%' PRINT 'has (at least)5 numbers'SET @foo = 'asdasd2asda1asfdf5gsdf3asdasd'IF @foo LIKE '%[0-9]%[0-9]%[0-9]%[0-9]%[0-9]%' PRINT 'has (at least)5 numbers' Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|