SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Extracting string after and before a Character/Pattern

By Srikanth,

Usually we see lof of codes flying around for this extraction.Most of them difficult to remember.
An easy way is to get hold of the basics.
Function used : SUBSTRING,CHARINDEX
Substring syntax : SUBSTRING(string to search, position to start, length of characters to be extracted)
CHARINDEX (character to search, string to search) returns the position of the character in the string.
If we want to extract before the character you would put the charindex as the number of characters and start position as 0 in the substring function

Total article views: 1611 | Views in the last 30 days: 3
 
Related Articles
FORUM

Problem segregating third occurence from a column

Charindex ,substring

FORUM

substring more than 4000 characters

i need to substring the data which has more than 4000 characters

FORUM
FORUM

substring

using substring to parse data from string

FORUM

SubString

Assistance with SUBSTRING in SSIS Expression in Derived Column Transformation

Tags
characters    
charindex    
patindex    
sql    
substring    
t-sql    
 
Contribute