Questions tagged [patindex]
151 questions
0
votes
1 answer
Replace pattern with value
How can I replace the $SV### value in this string example if I don't know what the numbers following will be? Or even just get the 1234544 into another string variable.
I tried this but it doesn't replace anything:
declare @string…

grc
- 19
- 2
0
votes
1 answer
PATINDEX does not recognize dot and comma
I have a column that should contain phone numbers but it contains whatever the user wanted. I need to create an update to remove all the characters after an invalid character.
To do this I am using a regex as PATINDEX('%[^0-9+-/()" "]%', [MobilNr])…

Dan
- 683
- 2
- 8
- 24
0
votes
3 answers
How to convert a date 15-May-2019 in SQL to 2019/05/15 using PATINDEX
I need to convert a date in SQL. The date as is 15-May-2019 and it should display as 2019/05/15.
This is the code I have so far
CASE WHEN WHEN LEN(AgeGroup) > 1 THEN PATINDEX ('%[A-Z]%', date)
I'm not completely sure how to use Patindex. Can…

Luna
- 3
- 1
0
votes
3 answers
How to identify and redact all instances of a matching pattern in T-SQL
I have a requirement to run a function over certain fields to identify and redact any numbers which are 5 digits or longer, ensuring all but the last 4 digits are replaced with *
For example: "Some text with 12345 and 1234 and 12345678" would become…

Nyk
- 33
- 5
0
votes
2 answers
PATINDEX Number/range of wildcard characters
In regex we have syntax for occurrence of any characters between 'a' and 'b' that goes like this:
/a.{5,15}b/
but we were able to specify minimum of characters between them (5) and maximum (15).
Is there any equivalent to specify range of wildcard…

Jahusek
- 117
- 13
0
votes
0 answers
How to improve this match pattern?
This pattern works as expected. I want to improve it by:
Merging the repeating patterns : [0-9][0-9][0-9] into one. I tried
[0-9{3}], no success.
Specify the special character - instead of [^0-9A-Z]
SELECT…

Rick
- 55
- 1
- 12
0
votes
1 answer
SQL: Extract numbers from string using Patindex-function
string #1: King's road 8
string #2: Abbey road5
string #3: Carnaby Street 18-20a
string #5: //
string #5: Baker Str. 21a-21e
and split them up into:
colA:
King's road
Abbey road
Carnaby Street
//
Baker Str.
colB:
8
5
18-20a
NULL
21a-21e
I am…

DaveS
- 53
- 1
- 9
0
votes
1 answer
How to use PATINDEX in SQL Server?
In SQL Server 2012, I have a column which has long text data. Somewhere within the text, there is some text of the format
{epa_file_num} = {138410-81}
If it exists, I want to extract out 138410-81 as a column value. In regular JS regex, I would use…

omega
- 40,311
- 81
- 251
- 474
0
votes
1 answer
Using PATINDEX to find times within text in SQL Server using multiple formats
I need to use a regular expression which returns the time of format 12:43 AND 1:33, I tried the following, and each one returns the desired results, how can I combine both so SQL can return either the first OR the second :
set @reg =…

Hayan Al Mamoun
- 43
- 1
- 5
0
votes
1 answer
How to remove prefixed numbers from a varchar in SSIS?
I have an SSIS package which copy data from text file to a table in sql server.
I use 3 tasks for the same 1)Flatfile Source 2) Derived Column task, 3) SQL Destination task
In the 3rd task..I specify the table...into which I have to copy the…

Relativity
- 6,690
- 22
- 78
- 128
0
votes
2 answers
SQL Server: extracting $#,### from a string
I'm trying to extract a dollar value from a string using a mixture of substrings, charindexes, and patindexes. I can seem to extract the $###,### pattern from all string except when it falls at the end of the string.
Here is some code with test…

Richard Wolff
- 35
- 4
0
votes
1 answer
PATINDEX incorrect result when looking for dash character "-"
This simple example shows the issue I've run into, but I don't understand why...
I'm testing for the location of the first character that is either a lower or upper case letter, a single dash, or a period in a string parameter passed to me.
These…

Brian B
- 1,509
- 3
- 20
- 29
0
votes
0 answers
SQL Server function PATINDEX in PostgreSQL?
In SQL Server I execute:
select PATINDEX('%\%[0123456789][\ ]%', N'\deftab1134\paperw12240\paperh20000\margl900\margt1440\margr540\margb1440\plain\f1\fs24 That is my report');
---
1
It is correct. I need the same function in PostgreSQL.
I have…

ZedZip
- 5,794
- 15
- 66
- 119
0
votes
1 answer
How to use substring to put the date from these numbers
how to pull the date (20060807) of these numbers
1.2.840.113782.1.3.5.8696.41870.20060807.69548508
1.2.840.113782.1.3.1.JDI.65.1.2002816.205431857…

Jason312
- 197
- 1
- 1
- 10
0
votes
1 answer
SQL loop to find all occurrences of a string expression in a DB field
I have a varchar(max) field in an SQL Server DB table and I would like to find all occurrences of a string within this field and 50 characters either side to give it context when reading.
I have done this using the code below, but now i would like…

Simon
- 1,293
- 5
- 21
- 39