The CHARINDEX function searches a character string for the first occurrence of a target substring, where the search begins at a specified or default character position within the source string.
Questions tagged [charindex]
274 questions
2
votes
1 answer
SQL query for parsing a body of text to extract a string from a list
I need help on an SQL query to perform the following:
I have a table with a list of possible string values for products.
I have a second table with free form text in which this product may be mentioned. Is there any way an SQL query can extract the…

Manus
- 869
- 2
- 10
- 20
2
votes
0 answers
Wierd behavior on CharIndex on Nchar on SQL Server
I have faced a weird behavior, look at this query
declare @t nvarchar(50)
set @t = N'Hello'+nchar(8204)+N'World'
select charindex(nchar(8204),@t)
this query returns 0 as the result, while I have added nchar(8204) in the middle of the…

Reza
- 18,865
- 13
- 88
- 163
2
votes
2 answers
Get only numeric part of a column data?
I have a column in my database containing both numeric and alphanumeric characters.
I only want to get the numeric (6 numbers) from the column.
Example of data:
TEST_123456_Prod
DB111111P
F222222FN
PROD999999_SCF
I want to create a select…

user3519275
- 138
- 2
- 9
2
votes
3 answers
SQL Server rtrim ltrim and charindex
I have the following scenario
John Doe johndoe@email.com
john johndoe@email.com
I want away that I can detect the first right space and just exclude everything to the left so I just get the email address of the person. So:
John Doe johndoe@email.com…

daw dasf
- 35
- 6
1
vote
3 answers
Negative indexing with charindex() and substring function
I have a column that holds the data in the following format:
Field Name
123_456_ABC_DEF
12_34_456_XYZ_PQR
LMN_OPQ_123_456
In each case I require, the last two block of data i.e.
ABC_DEF
XYZ_PQR
123_456
Is there a way to use charindex() in manner…

noob
- 47
- 5
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
3 answers
How can I use SQL Substring to extract characters from this filename?
I'm attempting to use the SUBSTRING function to extract a name out of a filename.
An example filename would be: "73186_RHIMagnesita_PHI_StopLoss_TruncSSN_NonRedact_Inc_to_Apr2022_Paid_to_Apr2022_EDIT"
I'm attempting to extract the "RHIMagnesita"…

Austin
- 39
- 5
1
vote
2 answers
SQL to determine which rows to retain and which to remove
Good Morning Everyone,
I am having a bit of a mental block and was going to see if anyone can help me. I have a table that inventories PDF Files that our office creates. We have changed the naming convention and I am trying to develop logic that…

Eric G
- 55
- 5
1
vote
1 answer
How to use substring/charindex to extract a date from a ntext column?
Example of column I'm pulling from
SE IRS REC Ccy: USD Face Value: 30,000,000.00 Intr Rte: -2.386000% Pmu/Dsc: -63,130.00 INTEREST ACTUAL/360 Bndswp Int: 2,135.40 …

Jason
- 11
- 2
1
vote
1 answer
Extracting Portions of String
I have a field with the following types of string
X000233756_9981900025_201901_EUR_/
I firstly need to take take the characters to the left of the first _
Secondly I need to take the characters between the first and 2nd _
First _ is…

Geoff Codd
- 15
- 3
1
vote
4 answers
Function which returns a TABLE after splitting a string
I want to create function which returns a table with two columns extracted from an input string.
As an input, the function gets a string like:
'@Name=John;@Secondname=Kowalsky;@Mail=example@mail.com;'
The function is supposed to create from this…

Forey
- 81
- 7
1
vote
2 answers
How to use Charindex for one or the other character
I have a string with a bunch of numbers but it contains one letter somewhere in the center of the string. This letter can either be 'A' or 'B'. I am trying to find out the position of this letter with the Charindex() function. However it doesn't…

not_ur_avg_cookie
- 303
- 4
- 15
1
vote
1 answer
charindex in case expression
I am fairly new to SQL Server and was given the below case statement and I am having a hard time understanding what its doing.
I think its taking the 835 column checking to see if the claim value is (greater then 1) and if so then to relook at that…

cardonas
- 109
- 1
- 1
- 9
1
vote
2 answers
SQL I need to extract a stored procedure name from a string
I am a bit new to this site but I have looked an many possible answers to my question but none of them has answered my need. I have a feeling it's a good challenge. Here it goes.
In one of our tables we list what is used to run a report this can…

almostanexpert
- 13
- 2
1
vote
0 answers
How to find the position of a specific character in a string with sparql
I'm trying to find a solution to find a character in a sting with sparql.
I tried the following code but there seems to be no option like CHARINDEX in SPARQL.
I want to find the position of the last "/" used in the URI (which i stranslated to a…

Ad Reuijl
- 11
- 1