patindex

PATINDEX with letter range exclude diacritics (accented characters)

瘦欲@ 提交于 2021-01-02 08:16:57
问题 I am trying to figure out how to use a patindex to find a range of letter characters, but exclude accented characters. If I do a straight search, using the default collate (insensitive) works just fine. However, when I search a range of letters, it will match on the accented character SELECT IIF('Ú' = 'U' COLLATE Latin1_General_CI_AI, 'Match', 'No') AS MatchInsensitive, IIF('Ú' = 'U' COLLATE Latin1_General_CI_AS, 'Match', 'No') AS MatchSensitive, PATINDEX('%[A-Z]%', 'Ú' COLLATE Latin1_General

PATINDEX with letter range exclude diacritics (accented characters)

南笙酒味 提交于 2021-01-02 08:15:28
问题 I am trying to figure out how to use a patindex to find a range of letter characters, but exclude accented characters. If I do a straight search, using the default collate (insensitive) works just fine. However, when I search a range of letters, it will match on the accented character SELECT IIF('Ú' = 'U' COLLATE Latin1_General_CI_AI, 'Match', 'No') AS MatchInsensitive, IIF('Ú' = 'U' COLLATE Latin1_General_CI_AS, 'Match', 'No') AS MatchSensitive, PATINDEX('%[A-Z]%', 'Ú' COLLATE Latin1_General

Search SQL Server string for values from another table

爱⌒轻易说出口 提交于 2020-01-17 13:27:34
问题 I have a table with column name that has random characters before and after the name ie: Table A : Name ----------------- asd4345JONlkj345 .;lidDavidlksd$ and I have another table in same DB that has the names ie: Table B : Name ------ David Jon This goes on like this for 30k rows or I'd just hardcode something really quick. I want to search each string in Table A 'Name' column for each value from Table B, and if found return the name in a new column. I have a feeling this will be a UDF,

Search SQL Server string for values from another table

谁说胖子不能爱 提交于 2020-01-17 13:27:10
问题 I have a table with column name that has random characters before and after the name ie: Table A : Name ----------------- asd4345JONlkj345 .;lidDavidlksd$ and I have another table in same DB that has the names ie: Table B : Name ------ David Jon This goes on like this for 30k rows or I'd just hardcode something really quick. I want to search each string in Table A 'Name' column for each value from Table B, and if found return the name in a new column. I have a feeling this will be a UDF,

How to search a string and return only numeric value?

最后都变了- 提交于 2020-01-07 09:52:35
问题 I need to create a formula column. In this column I need to return a numeric value. Example: database.dbo.table1 has a column called "message" that contains a long message. The message is formatted as so: various words, characters, spaces <this document is> document# = 12345 <this document is> What I need to do is search through the message, find "this document is" and searched between both of those phrases for the numeric value of the document, return the document # inside the formula column

extract a string from a stored proc definition

泪湿孤枕 提交于 2020-01-03 05:29:06
问题 I need to check the library used by several stored procs that extract data from a remote server. I have (with SO help, see SO 21708681) built the below code: DECLARE @tProcs TABLE ( procID int IDENTITY, procObjectID nvarchar(100), procName nvarchar(100) ); insert into @tProcs SELECT object_id, name FROM sys.objects WHERE type in (N'P', N'PC') and name like '%_Extract' declare @countProcs int, @I int=0 select @countProcs=COUNT(*) from @tProcs while @I<@countProcs Begin declare @source_code

Escaping ] and ^ characters in a T-SQL “pattern” expression character class

梦想与她 提交于 2019-12-20 02:28:29
问题 I'm trying to emulate Oracle's RTRIM(expression, characters) in MsSql Server 2008 R2 with the following query: REVERSE( SUBSTRING( REVERSE(field), PATINDEX('%[^chars]%', REVERSE(field)), LEN(field) - PATINDEX('%[^chars]%', REVERSE(field)) + 1 ) ) The problem is that I want to be able to trim characters like ] and ^ which do probably need escaping. I don't know how to do this. Things like \] don't work. I'm aware of the ESCAPE clause but I do not understand exactly how it works and, by the way

Select query to remove non-numeric characters

淺唱寂寞╮ 提交于 2019-12-16 22:51:12
问题 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

How to match all characters except right crotchet (close square bracket) with SQL's PatIndex?

跟風遠走 提交于 2019-12-13 02:34:58
问题 In the below code example, all results should return 7. Those with aliases beginning X however, do not. select --where matches patindex('%-%' ,'111111-11') dash --not a special character, so works without escaping ,patindex('%[%' ,'111111[11') xLeftCrotchet --special character [ not escaped; works ,patindex('%[[]%','111111[11') leftCrotchetEscaped --special character [ escaped to [[]; doesn't work ,patindex('%]%' ,'111111]11') rightCrotchet --special character ] not escaped; doesn't work

REGEXP_LIKE conversion in SQL Server T-SQL

泪湿孤枕 提交于 2019-12-09 03:17:05
问题 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,