patindex

REGEXP_LIKE conversion in SQL Server T-SQL

我的梦境 提交于 2019-12-01 06:41:53
I have come across this line in an old report that needs converting to SQL Server. REGEXP_LIKE (examCodes, learner_code) examCodes being the source and learner_code being the pattern. I know that SQL Server doesn't have REGEXP_LIKE and most places tell you to use PATINDEX. Here's me thinking that this would work: PATINDEX(learner_code, examCodes) But I get the error: Msg 4145, Level 15, State 1, Line 54 An expression of non-boolean type specified in a context where a condition is expected, near 'WHERE'. On MSDN the syntax is specified as, PATINDEX ('%pattern%',expression) But learner_code is a

T-SQL select query to remove non-numeric characters

試著忘記壹切 提交于 2019-11-26 05:17:46
I've got dirty data in a column with variable alpha length. I just want to strip out anything that is not 0-9. I do not want to run a function or proc. I have a script that is similar that just grabs the numeric value after text, it looks like this: Update TableName set ColumntoUpdate=cast(replace(Columnofdirtydata,'Alpha #','') as int) where Columnofdirtydata like 'Alpha #%' And ColumntoUpdate is Null I thought it would work pretty good until I found that some of the data fields I thought would just be in the format Alpha # 12345789 are not... Examples of data that needs to be stripped AB