Questions tagged [patindex]
151 questions
0
votes
1 answer
Need to convert SQL scalar-value function with PATINDEX to VB equivalent
Long time reader, first time poster. Sorry in advance for the wall of text.
Short version: I need to know how to use VB's Instr (or some other VB function) to search a string and return the index of the first occurance of any one of three symbols in…

Voysinmyhead
- 1,315
- 1
- 10
- 18
0
votes
1 answer
Replacing column from query via patterns
How to replace all column in the string
DECLARE @invalidColumns varchar(200) = 'abc, xyz'
DECLARE @sqltext varchar(max) = '((abc = ''sometext'') OR (xyz = '' some more text'')) OR
(pqr = ''vb'') AND ( abc != '' …

Zerotoinfinity
- 6,290
- 32
- 130
- 206
0
votes
1 answer
How to remove special characters from the string in sybase using patindex
i am having data wich consists of special characters but my output should not display that special characters or ascii characters . I need only alphanumerics and spaces allother character should be replaced with null . Please suggest some way to…

Ramesh
- 123
- 2
- 5
- 15
0
votes
1 answer
SQL Server PATINDEX to match exact string
SELECT * FROM SYS.COLUMNS WHERE
NAME NOT IN (SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'XXXX'
AND PATINDEX('%' + COLUMN_NAME + '%', 'ABC;XYZ') <> 0);
In Table XXXX there are columns like XY,AB,ABC,XYZ. Now I only want…

Soham Dasgupta
- 5,061
- 24
- 79
- 125
0
votes
1 answer
Query genereated by Entity Framework using PatIndex not working
I have a query generated by EF5 code where I'm using SqlFunctions.PatIndex and the query takes 5 minutes to run. If I make a change to the SQL to use like operator instead then it works sub-second time. From what I've read PatIndex is supposed to…

BlackICE
- 8,816
- 3
- 53
- 91
0
votes
2 answers
Add values show into single column in sql server
In my table, I have Experience field like
Experience
5Years0Months
2Years0Months
Here I want to convert into seconds then add Years and Months into a single column.
Experience - [Some value]
So i create one query like following,
select…

PoliDev
- 1,408
- 9
- 24
- 45
0
votes
3 answers
Patindex in SQL Server 2008 R2
I am trying to use the PATINDEX function in SQL Server 2008 R2 to extract the value 3 from the string
Charged Hourly Fee for 3 CR for BCP202DL Personal Development II
but I seem to be making a mistake.
I tried
SELECT PatIndex('%[0-9]%', 'Charged…

James Obuhuma
- 397
- 3
- 8
- 20
0
votes
1 answer
Regarding sql server table column search with PATINDEX
i have never use PATINDEX() but i hard the table data can be search with PATINDEX().
often i got requirement to search multiple column of any table then i write the sql like
SELECT * FROM ADDRESS WHERE
((NAME LIKE 'Bill%') OR (CITY LIKE 'Bill%') OR…

Thomas
- 33,544
- 126
- 357
- 626
0
votes
1 answer
SQL Server Reverse Octets in IPv4 Address?
I have some dumps from a Microsoft TMG log table, the IP address is stored as a uniqueidentifier. I was able to convert the values into human-readable "dotted octet notation" (this is all IP v4 stuff), but the values are coming out reversed.
What is…

Snowy
- 5,942
- 19
- 65
- 119
-1
votes
1 answer
Postgresql query to MySQL refactor
I have a Psotgresql query and I need it for MySQL, is it possible to refactor this code to work on MySQL?
CREATE FUNCTION patinde(pattern VARCHAR(12), expression VARCHAR(12) ) RETURNS INT
SELECT
COALESCE(
STRPOS(
…

Efrain Mejia
- 9
- 2
-1
votes
2 answers
Why is the PATINDEX returning wrong results?
I am trying to extract the date from a string. I am using the below mentioned query using both SUBSTRING and PATINDEX:
SELECT Message, SUBSTRING(Message, PATINDEX('%[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]%', Message), 10) as Month_Captured
I am…

Yash
- 319
- 1
- 4
- 6
-1
votes
1 answer
T-SQL Char index patindex
Does anyone have script that can pull out data held in the columns to split out the servernames in to their own columns?
| ID| Servers
|:-:|---------------------------------------------------------------------------------
| 1 | …

Dave Carpenter
- 41
- 1
- 1
- 4
-1
votes
2 answers
Regex in TSQL used to match contents of a given parameter not working
I am trying to check if a given parameter in a SP is eligible to be used and I have the following REGEX:
[a-zA-Z][a-zA-Z]\d{4}|[a-hA-H]\d{3}|[j-mqrtvwzJ-MQRTVWZ]\d{4}
It supposed to find a match for entries like xx9999 and x999. I tested it in…

Yan Kleber
- 407
- 2
- 4
- 11
-1
votes
1 answer
getting the second occurrence of a substring with PatIndex
With this query I get the postal code from an address and it works, but there are some cases where the address number's length is 5 and so I get this instead of the postal code, is there any chance to get the last occurrence with PatIndex?
SELECT…

marko
- 487
- 1
- 6
- 15
-1
votes
3 answers
T-SQL Extract Numbers from a string and everything in between
I'm using SQL Server 2014.
I understand how to extract numbers from a string using PATINDEX (Query to get only numbers from a string), however, how would I also include if they was actually a string value between the numbers that I also need to…

Michael
- 2,507
- 8
- 35
- 71