Questions tagged [patindex]
151 questions
0
votes
1 answer
In a Databricks SQL endpoint, didn't find SQL server PATINDEX equal function in databricks
SQL Server
Ex:- SELECT PATINDEX('%[0-9]%', 'Apple5Ball6') Test
Result:- 6
How can we get same result in Databricks SQL end point?

Rajashekhar
- 75
- 11
0
votes
0 answers
Splitting an address string in SQL
I have a table called CUSTTABLE on an sql server database that has a column containing addresses. In the Netherlands the street name always comes before the house number and then the apartment information if it's an apartment. I want to separate the…
0
votes
0 answers
Charindex function that can search for multiple values values in a string
I'm trying to clean this data set and the home#dest column is giving me some issues. I would like to turn the one column into 4. they would be Homecity, Homestate/country, Destcity, and Deststate/country. I've tried many different combinations of…

Darnell
- 1
- 1
0
votes
2 answers
Extract substring from SQL Server column
I am trying to figure out how to extract a substring from a column in SQL Server. I very much would like to be able to do it directly in SQL if at all possible. The content of my column holds the responses of a web form and looks like…

Wilmar
- 558
- 1
- 5
- 16
0
votes
0 answers
How can I get this pattern using PATINDEX?
I am trying to capture a specific sequence of characters: number (1 or two digit), space, minus, space, number (1 or two digit) but I can have some text before and/or after the sequence.
Examples:
abc 2 - 5
abc 5 - 10 def
abc 15 - 25
abc 15 - 25…

Baro
- 5,300
- 2
- 17
- 39
0
votes
1 answer
t-sql How to use name column in patindex
could you help me with such question:
I have such request
with a as
(
select 1 num, 21 q, 49 b, 100 scq, 155 o, '49 55;' b_ost
union
select 2 num, 21 q, 50 b, 101 scq, 155 o,'50 54;49 55;'
union
select 3 num, 21 q, 48 b, …

kir kir
- 3
- 2
0
votes
1 answer
Find volumes by keying in on Units of Measure, but when there's two?
I have a string like below:
194736 BBLS FLUID 3800880 LBS 40/70 361060 LBS
I have used the following to fish out the '3800880' where I used a function to grab the right most word to the left of the 'LBS'. This does a decent enough job about finding…
0
votes
3 answers
How to remove Roman letter and numeric value from column in SQL
Using SQL Server, I have a column with numeric and Roman numerals at the end. How do I remove the numeric alone without specifying the position?
Job_Title
Data Analyst 2
Manager 50
Robotics 1615
Software Engineer
DATA ENGINEER…

lava_kkk
- 5
- 2
0
votes
5 answers
Getting date from format yyyy_d_m
In SQL Server, I have a column containing a string formatted as yyyy_d_m_(randominteger)_(randominteger)_blahblahblah string.
So
column
2021_28_6_42_blahblahblahblah
2021_8_12_17_4_blahblahblahblah
etc.
I need to retrieve everything…

elboi
- 1
- 2
0
votes
1 answer
Is there a simplification of this patindex code possible?
I've been looking for a way to simplify the patindex code below, but haven't succeeded yet. Is there anyone who can tell me if this is possible witin SQL Server.
patindex('%'+'('+'[0-9][0-9]'+'/'+'[0-9][0-9]'+'/'+'[0-9][0-9][0-9][0-9]'+' -…

vvanasperen
- 53
- 8
0
votes
1 answer
SQL Server : Request for extracting the strings following each occurence of same substrings
I have a string with this format
"AB=10,AC=11,AC=12,AC=13,AD=14,AD=15,AD=16"
and I would like to put the numbers in different columns, giving to each column the name you can find in the string before the =associated with this number.
So here, I…

Jonathan
- 97
- 7
0
votes
3 answers
SQL SUBSTRING & PATINDEX of varying lengths
SQL Server 2017.
Given the following 3 records with field of type nvarchar(250) called fileString:
_318_CA_DCA_2020_12_11-01_00_01_VM6.log
_319_CA_DCA_2020_12_12-01_VM17.log
_333_KF_DCA01_00_01_VM232.log
I would want to…

Stpete111
- 3,109
- 4
- 34
- 74
0
votes
1 answer
Explain where trailing spaces are and aren't ignored in SQL Server
I believed trailing spaces are ignored in SQL everywhere until I encountered a scenario with PATINDEX where they aren’t ignored.
Case 1: SELECT PATINDEX('qwerty', 'qwerty') returns 1.
Case 2: SELECT PATINDEX('qwerty', 'qwerty ') returns 1. A…

aditya
- 15
- 4
0
votes
1 answer
Use PATINDEX to extract a substring in SQL Server?
I have some specific values I want to extract out of a string in SQL Server, but I'm not sure exactly how to get it done with PATINDEX.
Take this string:
declare @Command nvarchar(500) = 'IF dbo.SomeFunctionFn() = 1 BEGIN EXEC SomeStoredProcPR…

Modern Viking
- 141
- 9
0
votes
2 answers
Split String based on position and delimiters
I am in need of assistance.
A question about SQL on CHARINDEX, PATINDEX, SUBSTRING, LEFT and RIGHT.
I have strings that I need to split based on position and delimiter. Using some of it as Column name and the other part as data. and group this based…

Sam
- 57
- 1
- 7