Questions tagged [charindex]

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.

274 questions
31
votes
2 answers

What is the CHARINDEX (SQL SERVER) equivalent in POSTGRESQL?

I am trying CHARINDEX in Postgresql. But it says: function CHARINDEX() does not exist If no such inbuilt function exists in postgresql, then is there any function that serves as an alternative to charindex? If yes, What is the CHARINDEX (SQL…
Manoj Soundararajan
  • 371
  • 1
  • 3
  • 13
7
votes
1 answer

TSQL - Cannot find unicode char with CHARINDEX

I cannot find a special Unicode char in a string with TSQL - CHARINDEX declare @n nchar(1), @str nchar(20) set @n = nchar(8237) select 'x'+@n+'x' set @str = N'43‭0'+@n+N'22‬' -- after "3" there is also an unicode 8237 char select charindex( @n …
Mustafa
  • 85
  • 4
6
votes
3 answers

Return Word in String - SQL

I am using SQL Server, how can I return the account numbers from the below string in SQL? Below is all in 1 column and 1 string of NVarchar() Bank Name: eewweew Chemnitz Bank Account Address: weweweewew Zwickau 12345 dfdfdfdfd fdfdfdfdf. 1-3…
Etienne
  • 7,141
  • 42
  • 108
  • 160
4
votes
1 answer

in vb6, how to query access records, then order by specific ids

select * from [main] where id in (33,11,22) order by id if i using this query, i will get the recordset order by this: 11 22 33 but i want to the return recordset by this order (same as id in (33,11,22) order): 33 11 22 by google i understand we…
user1928432
  • 133
  • 1
  • 9
4
votes
2 answers

How to select a string between 2 identical characters in SQL

My initial string is Content-Disposition: attachment; filename="0001.zam" I want to select everything between the two " characters ("0001.zam" in this case). I know that I need to use the SUBSTRING and CHARINDEX functions similar to: SELECT…
DanteeChaos
  • 313
  • 1
  • 6
  • 19
4
votes
1 answer

Using CHARINDEX and SUBSTRING in a CASE statement

I need to evaluate a field with a CASE statement. The field name is Commodity and is a varchar(255). The values differ and I need to extract a specific portion from it after a specific character. The character is a '>'. I was able to come up with…
tsqln00b
  • 355
  • 1
  • 4
  • 20
4
votes
3 answers

SQL Parse out multiple substrings

I have a very long and complex string that comes in with New line breaks - I am having a hard time parsing. I need to be able to create a select query with a column for each of the below fields. The ideal would be find the new line break - for each…
Elizabeth
  • 719
  • 1
  • 14
  • 27
3
votes
1 answer

SQL Server - CHARINDEX on ASCII values

I have a column on a SQL Server table that has a lengthy value with line breaks. I am trying to find the values before each line break. EXAMPLE: --Column name: ItemDescription Case Qty: 12 Weight: 8 oz. Flavor code: PB Size: STOCK Cut: 1/8" x 1/8"…
Crazy Cucumber
  • 479
  • 8
  • 36
3
votes
1 answer

SSIS - Derived Columns - Case Statment - Charindex and Substring

I've the fololwing transformation in T-SQL: SELECT [FIELD_A] = case when CHARINDEX('-', FIELD_B)>0 then LEFT(FIELD_B,CHARINDEX('-', FIELD_B)-1) else FIELD_B end, How can I put this into a expression in Derived Column object using SQL Server…
Pedro Alves
  • 1,004
  • 1
  • 21
  • 47
3
votes
2 answers

CHARINDEX returns the wrong result in some COLLATIONs when searching for thorn (character 254)

Overview CHARINDEX is returning the wrong value occasionally when using a collation sequence like: Latin1_General_CI_AS but works with a collation sequence like: SQL_Latin1_General_CP1_CI_AS This has been encountered on MS SQL Server 2008 R2 and…
Gazza
  • 41
  • 5
3
votes
1 answer

tsql - extract string using SUBSTRING

I have a column where I need to extract the remainder of a string starting from "_". Example below: TF_Bskt Trade would need to be "Bskt Trade" SSC_Equity would need to be "Equity" etc ...... So I've got this far using the TF_Bskt Trade…
chrissy p
  • 823
  • 2
  • 20
  • 46
2
votes
1 answer

T-SQL SUBSTRING with CHARINDEX AS LENGTH part is returning too much text

I have ploughed through the massive amount of queries on here relating to SUBSTRING and CHARINDEX but I cannot find one that answers my query. I am extracting a single part of a long piece of text but it is returning 48 characters too much. E.g. in…
2
votes
1 answer

SQL Dynamically Split Values into new columns

Have a table that contains different IP values for objects separated by commas. Looking for way to split them dynamically into new columns. For example, 10.12.11.20, 192.168.1.3, 192.168.1.4 192.168.1.50, Based on the results returned in the table…
Sling4778
  • 21
  • 4
2
votes
2 answers

How to use RegEx in the SQL function CHARINDEX to find the nth occurrence

The intent of the following algorithm is to extract certain set of fields from a key (in this example, extract first 2 fields), and it works. The fields are delimited by a colon: declare @key nvarchar (max); declare @pos int; declare @fields…
Noble
  • 135
  • 1
  • 11
2
votes
5 answers

distinct and sum if like

I have a table as the following name ----------- 1@apple@1 2@apple@2 3@apple@4 4@box@4 5@box@5 and I want to get the result as: name -------------- apple 3 box 2 Thanks in advance for your help
refaelo1979
  • 49
  • 2
  • 10
1
2 3
18 19