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.

226 questions
23
votes
1 answer

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
  • 291
  • 1
  • 2
  • 13
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
  • 6,621
  • 40
  • 99
  • 154
5
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
  • 55
  • 2
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
  • 255
  • 1
  • 3
  • 19
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
  • 627
  • 11
  • 26
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
  • 449
  • 8
  • 30
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
  • 846
  • 12
  • 27
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
  • 4
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
  • 792
  • 2
  • 16
  • 44
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
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
2
votes
1 answer

Performance tuning on matching word using CHARINDEX and COLLATION

I have two tables with following records: Table 1: 100 rows Table 2: 50 Millions rows Example: Table 1: tb100 create table tb100 ( name varchar(50) ); insert into tb100 values('Mak John'),('Will Smith'),('Luke W')......100 rows. Table 2:…
MAK
  • 5,596
  • 16
  • 61
  • 105
2
votes
2 answers

Extract all the characters after a position or index value in SQL Server

The below is a sample data 100231|ABC Limited||Liquidated|514321||AU||Testwood|5165|5/14/1996 12:00:00 AM|8/1/2003 12:00:00 AM|Test1|Test2| I want to extract all the data after position 12 of '|' pipe delimiter using SQL Server functions i.e. the…
2
votes
1 answer

How to find only last part of string with brackets using MS SQL

I have a long string with multiple bracket inside string , i am tried to fetch only last part of the string , But i have achieved first part till end. Alkyl acrylate-Styrene (or alpha-Methylstyrene) copolymer (Substances not requiring…
user9912287
2
votes
4 answers

Extract characters from string using SQL

I have a column of ID's and I am needing to use SQL to extract the first two characters after the " - " I am using the Custom SQL Query in Tableau 10.4 Example Column: ABC - BCA - IT AD - HD - A QWE - QWE - E What I need: BC HD QW I have tried to…
user3381842
  • 21
  • 1
  • 4
1
2 3
15 16