Questions tagged [patindex]

151 questions
2
votes
2 answers

Optimal search string in the where clause

Want to search the string using PATINDEX and SOUNDEX within the WHERE clause or any optimal way. I have the following table with some sample data to search the given string using PATINDEX and SOUNDEX. create table tbl_pat_soundex ( col_str…
MAK
  • 6,824
  • 25
  • 74
  • 131
2
votes
3 answers

T-SQL PATINDEX Pattern of Seven Characters with at Least One Letter and One Number

I want to identify a chunk of seven characters within a text of any length: Starts with a letter Includes at least one number (anywhere) All letters are uppercase How would I represent this type of pattern with PATINDEX()? PATINDEX('%[A-Z]%',text)…
OverflowingTheGlass
  • 2,324
  • 1
  • 27
  • 75
2
votes
2 answers

using patindex to replace characters

I have a table with a name column in it that contains names like: A & A Turf C & D Railways D & B Railways I have the following query that will get me the correct columns I want select name from table where patindex('_ & _ %', name) > 0 What I need…
Sc-python-leaner
  • 259
  • 1
  • 2
  • 13
2
votes
1 answer

Need help removing functions from CASE WHEN

I have a situation where I have created script to select data in our company's environment. In doing so, I decided to use functions for some pattern matching and stripping of characters in a CASE WHEN. However, one of our clients doesn't want to let…
Jeff.Clark
  • 599
  • 1
  • 5
  • 27
2
votes
2 answers

Issue with patindex and unicode character '-'

I have a string called Dats which is either of the general appearence xxxx-nnnnn (where x is a character, and n is a number) or nnn-nnnnnn. I want to return only the numbers. For this I've tried: SELECT Distinct dats, Left(SubString(artikelnr,…
Cenderze
  • 1,202
  • 5
  • 33
  • 56
2
votes
2 answers

PATINDEX all values of a column

I'm making a query that will delete all rows from table1 that has its column table1.id = table2.id table1.id column is in nvarchar(max) with an xml format like…
Cyberpau
  • 125
  • 9
2
votes
3 answers

How to find and display all instances of a pattern in a SQL Server string?

So I am trying to write a UDF that will pull specific data from a string. 'random text here Task 1234 blah blah more text task 4567' I want to extract 'Task 1234 and task 4567' and have them display like such 'Task 1234, task 4567' Here's…
user3486773
  • 1,174
  • 3
  • 25
  • 50
2
votes
3 answers

MSSQL select substring according to this pattern

I have to ask you for something which is connetced with MSSQL. So, I've got one column named Command(VARCHAR) which is a part of some table named TB_Commander. This Column include results for example like (rows): 1.Delete o:2312312, c=312321 2.Add…
2
votes
2 answers

SQL PATINDEX patterns for filtering

I am trying to filter a string to be used for as a subject line for Outlook mail. I use a filter b/c some strings that have special characters will convert a subject line into Unicode which I want to prevent. I am trying to use PATINDEX but can…
Angel Cloudwalker
  • 2,015
  • 5
  • 32
  • 54
2
votes
1 answer

Extract a value from a string in a table?

I am trying to extract a value from a string in a table like this below, query table, query_id value 1 type={"page":"page"}&parent_id=10&image=on&content=on 2 type={"page":"page"}&parent_id=self 3 …
Run
  • 54,938
  • 169
  • 450
  • 748
1
vote
1 answer

Is CHAR(14) not allowed in SQL Server T-SQL patindex range?

What's the problem with CHAR(13) or perhaps CHAR(14) in TSQL patindex? As soon as I include CHAR(14) in a pattern, I get no records found. Searching for an answer, I just found my own question (unanswered) from 2009 (here:…
Andreas Jansson
  • 830
  • 1
  • 9
  • 21
1
vote
1 answer

How do i pull the next 2 words after a specific string?

I am spending a long time on how to pull part of a long string in T-SQL. I need to pull the person after "Eaten by" string. In this case, the first string below will be Smith, John and for the second string it will be Bloggs, Joe Each string length…
Paulo
  • 13
  • 3
1
vote
2 answers

Select specific portion of string using Regex match

Please consider the below table. I am trying to retrieve only the EUR amount within the Tax strings. Some records vary more than the other in size, but the float numbers are always there. OrderID SKU Price Tax **** **** **** …
Brayn
  • 406
  • 4
  • 20
1
vote
1 answer

SQL Patindex / Regex - Match where there are 4 or less characters between 2 apostrophes

I have the following string: 'Siemens','Simatic','Microbox','PC','27','6ES7677AA200PA0','6ES7','677AA200PA0' I want to remove any "terms" that are less than 5 characters. So in this case I'd like to remove 'PC', '27' and '6ES7'. Which would result…
Lee
  • 1,485
  • 2
  • 24
  • 44
1
vote
2 answers

Find matching values between two tables when using cross apply in SQL

I am trying to extract 5 or more consecutive numbers from from Table A Column x and match the extracted numbers to Table B column z. If the value exists, that is fine but if the value does not exist it needs to be inserted into Table B. I have…
N101Seggwaye
  • 75
  • 2
  • 16
1
2
3
9 10