Настенный считыватель смарт-карт  МГц; идентификаторы ISO 14443A, смартфоны на базе ОС Android с функцией NFC, устройства с Apple Pay

Sql server substring after last character

Sql server substring after last character. SELECT SUBSTRING( string , LEN(string) - CHARINDEX('-',REVERSE(string)) + 2 , LEN(string) ) FROM SAMPLE; Where string is the string you want to split. R22818B17565C32G16SU. For example in the following numbers 72187-1 & 72187-2 I am interested in returning 1 & 2 Oct 7, 2022 · Another example: Result: a little lamb. TestString VARCHAR(50) ) INSERT INTO @testTable VALUES. The first part is not always fixed it can change. SELECT SUBSTR(description, -4) FROM student. the part after the last '\') : AdventureWorks_Data. Jul 31, 2013 · I need to get the substring from the second occurrence of _ till the end of string and as you can see the substring is not of fixed length. Searching from a position other than the first position. You can then run the following query to extract the 5 digits from the left (under the ‘identifier’ field): Copy. Mar 6, 2018 · Well you can do it by using something like this. SELECT position = PATINDEX('% [^ 0-9A-z]%', 'You are a prominent author at SQLShack!'); In the below example, we use the PATINDEX () function for a table column. com carmine32@hotmail. 1. t-sql. Bird USA-J. DECLARE @lastIndex int. Returns the whole string if the delimiter is not there. Perhaps make user function. 250 in 'Galerie Silk WHITE 250gsm SRA1 (4250 BP)' i am using the below to find the position of gsm however now i need to only return numbers after the last space. Duck USA-A. *)$ matches any characters that come next, putting them into a "capturing group" (basically a variable), followed by the end of the string Sep 4, 2015 · If your case is that simple (exactly one / in the string) use split_part():SELECT split_part(source_path, '/', 2) If there can be multiple /, and you want the string after the last one, a simple and fast solution would be to process the string backwards with reverse(), take the first part, and reverse() again: Oct 30, 2023 · FROM Product. Another example . Mouse USA-M. That will give you the 3rd position of the character, not the 2nd last. Hope it makes sense. [Split] ( @String VARCHAR(max), @Delimiter varCHAR(1) ) RETURNS TABLE AS RETURN ( WITH Split(stpos,endpos) AS( SELECT 0 AS stpos, CHARINDEX(@Delimiter,@String) AS endpos UNION ALL SELECT endpos+1, CHARINDEX(@Delimiter,@String,endpos+1) FROM Split WHERE endpos > 0 ) SELECT You can calculate it using the CHARINDEX() and the LEN() functions. I don't know how long the string in total will be, as A, B, C and D can differ in length, and the number of \ might vary as well. ,INSTR(mystring,',',1,2) AS second_comma. SELECT value, SUBSTR(value, 1, INSTR(value, '. As the third parameter, you can pass the index of the 'my specific string' you found: SELECT SUBSTRING(col, LEN(LEFT(col, CHARINDEX ('my specific string Nov 19, 2019 · Using substring with multiple identical characters. SET MyText = LEFT(MyText, CHARINDEX(';', MyText) - 1) WHERE CHARINDEX(';', MyText) > 0. Hot Network Questions Jul 24, 2014 · AS_CIS_Code column is of varchar (10) in added_services table. com How do I use Jul 23, 2013 · 4. I would like to use a regex like pattern. WHEN LEN(notes) < 50 OR (SUBSTRING(notes,50,1 SELECT RIGHT(RTRIM(column), 3), LEFT(column, LEN(column) - 3) FROM table. As of now I am using the following code to achieve it. Sep 11, 2012 · Table Email: Values: josh@yahoo. com test@hotmail. I have some key values that I want to parse out of my SQL Server table. The next part of your question seems to indicate that you want to split the entire thing up based on the - . Below i'm trying to show you one sample example how i want to get . 2. For the full prefix (and a variable PREFIX): var PREFIX = "test/category/"; str. The SQL below will extract the value: SET @InspectionId = CAST(SUBSTRING(@UserComment, @pos+LEN(@IdToFind)+1, (LEN(@UserComment) - @pos) + 1) AS INT) PRINT @InspectionId. Get substring between second and fourth slash. T-SQL substring between delimiters in middle of string. Here is a function. Mar 22, 2022 · SUBSTRING() is a text function that allows you to extract characters from a string. Jun 22, 2009 · 1. e. The first position of the string is one (1). Then what were the right (least significant) three characters is now the left (most significant) three characters. INSTR() can take a negative number for the position, which means it searches backwards. How to get last values in SQL Server 2008. Aug 19, 2009 · 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 @Louis, the substring syntax is as follows: SUBSTRING ( expression ,start , length ). For the last slash only, see Pedro's answer. The result would be: USA-T. 35. e. File21. Explanation of Query : Here Charindex find the '-' delimeter [length] IN Given String and now that Result [length+1] is our starting point and ending length is [len (col)-starting length] gives ending point and then use substring Function to Jun 8, 2017 · 3. Like it should be fetched as 'A_B_', 'A_B_C_', 'G_H_K_I_K_', 'U_Y_T_I_O Sep 15, 2017 · In SQL Server, given a string, is there an established, canonical "best" way to get a substring starting at a particular index, and continuing to the end of the string? "Best" here means a balance of the following considerations: Most efficient performance-wise; Easiest for developers to read and understand Dec 10, 2016 · Then take all characters up to that point. The first one is the field that we want to query on. Jul 25, 2012 · This can achieve using two SQL functions- SUBSTRING and CHARINDEX. Here is a sample: -- Sample data. DECLARE @testTable TABLE (. Then use that to start one position after and Mar 17, 2016 · But it returns the last part of the list just starting after the first comma occurrence. ,SUBSTR(mystring. It contains values like 'AB', 'ABC', 'GHKIK', 'UYTIOPJ' and so on which represents different codes. CHARINDEX returns the position of a text to search. SQL Server - substring from position to end of string. substring with variable last character SQL Server. If the length of your notes column is over 50, you can use CHARINDEX to find the next space after position 50 and SUBSTRING to that position. The position is the starting position where the substring begins. Edited: Following will remove the white space and returns lower case Nov 26, 2020 · Now I would like to get the substring before the last occurrence of \. Here is a SQL Fiddle. Keep in mind "start" and "length" can be expressions themselves as well, as long as they return a positive integer, negative integer or a bigint. lastIndexOf(PREFIX) + PREFIX. ------ Server. Aug 27, 2013 · Here I've passed 300 as a second parameter for substring function which means it will pick up to 300 characters after the ',' Substring and split in sql server. (The assumption is that the substring is a valid date) to_char(substring(val,position('-' in val)+1,8)::date,'yyyy-MM-dd') May 23, 2023 · G. I have included a sql fiddle link for you to see it in action sql fiddle. And then only take the the last one using rownumber. , column3. Example data: Desired result: My solution which removes every sub string after a dot: SELECT LEFT([Name], CHARINDEX('. B1444. . You can read strings to a variable as shown in the above answers, or can add it to a SELECT statement as below: SELECT SUBSTRING('Net Operating Loss - 2007' ,0, CHARINDEX('-','Net Operating Loss - 2007')) answered Feb 16, 2021 at 5:36. Would anyone advise on how to handle the later part of the logic . Increase the size of that first. substr(str. Apr 4, 2022 · If you value will always have at least 3 . A more professional programmer might code it this way: SUBSTR ( columnName, LOCATE ( '123', columnName ) + LENGTH ( '123' ) ) (It isn't really necessary when it's obvious that the Jan 9, 2014 · SELECT substring_index(your_column, '. And it's simple to get the 2nd or 3rd part etc. Jun 18, 2022 · The syntax of the function is: CHARINDEX(substring, string, start) However, if the function is not able to locate the substring in the string, it returns 0. Jul 27, 2015 · The issue is that the number of hyphens, product ID, and color code can all be different. General Grievance. answered Mar 6, 2018 at 14:15. The length argument is optional. the numbers i need to truncate look like this DOR-12345_X where _X is a revision letter. @LastIndexOf = LEN([MyField]) - CHARINDEX(@indexOf, REVERSE([MyField])) Haven't tested, it might be off by one because of zero index, but works in SUBSTRING function when chopping off from @indexOf characters to end of your string. SET @shiftPosition = @shiftPosition + 3 ---increment shift position by 3 for the new char and the chars that were already there. and not containing the ",". Basically i need the last block to get everything before the final space rather than after, so the length of the results never exceeds 50 characters. CASE. Dec 9, 2011 · @TimSchmelter - Any function can only follow a set of rules. Now I have to select these codes after modifying the above query so that '_' is appended after each character. Nov 18, 2019 · I need to perform a substring operation in SQL Server and get a string from start of hyphen character (-). SUBSTR and INSTR can also be used, however, by taking advantage of the 4th parameter of INSTR, nth_appearance: select INSTR(mystring,',',1,1) AS first_comma. Dec 6, 2011 · 3. SELECT SUBSTR('m_johnson_1234', INSTR('m_johnson_1234', '_', 1, 2)+1) FROM TABLE; For the start_pos argument use INSTR to start at the beginning of the string, and find the index of the second instance of the '_' character. Apr 15, 2014 · It answers your first question of extracting from after the last -of the string. Please note that there is a space before the 'a' in this string. Mar 25, 2013 · Remove characters after last slash in string Forum – Learn more on SQLServerCentral select SUBSTRING(@string,1, LEN(@string)-8) Lynn Pettis. A-S-ABC123-001. Declare @My_string = 'abc/def gh /ijk l/m/no p/qr. SELECT SUBSTRING ( 'SQL Server SUBSTRING', 5, 6) result ; Code language: SQL (Structured Query Language) (sql) Here is the output: result. @indexOf = <whatever characters you are searching for in your string>. substring. SUBSTRING(expression, start, length) For the expression argument, you write a string literal or specify a column from which you want to extract the substring. Its syntax is. SQL DBA,SQL Server MVP(07, 08, 09) A Nov 3, 2009 · 146. DavidG. For example, a,b returns b. C:\Program Files\Microsoft SQL Server\MSSQL\DATA\AdventureWorks_Data. , before . You may also want to retrieve a substring that doesn't end at the end of the string but at some specific character, e. Here is some code to verify the SQL above works: May 21, 2019 · A very straightforward answer to the specific data in this question: you could pass a third parameter to the CHARINDEX function call that looks for the CHAR(10) after a specific starting index. Now, both queries return the same because the numbering is 1 based, meaning that the first character in the expression is 1. Nov 30, 2016 · Here is my code but this trims everything after the @ and that is what i want. EG. Use LEFT combined with CHARINDEX: UPDATE MyTable. For example, SELECT SUBSTRING ('Hello World',1,5) will yield the result "Hello". com zehmaneh@yahoo. You can add a CASE statement or use NULLIF() in case the hyphen isn't always present: SELECT column1. mdf This technique can be used to extract just the filename (i. Compare last data and second last data sql server based on id. The function uses the text Nov 2, 2015 · SQL Server 2022 supports the following signature of STRING_SPLIT: STRING_SPLIT ( string , separator [ , enable_ordinal ] ) When enable_ordinal flag is set to 1 the result will include a column named ordinal that consists of the 1‑based position of the substring within the input string: Oct 17, 2019 · I use a combination of a table valued function to split the list into an ordered list. I will need to use this code in both SQL Server and MS Access. 0. END. */ matches any characters that come next, followed by a / which is the final / before the end of the string (and preceeding the bit that we want to extract) (. The length is the length of the substring. Aug 21, 2012 · How to get last character of a string in sql server. The SQL Server SUBSTRING function syntax is as follows: SUBSTRING (expression, position, length) Parameters: expression: Input source string. The following Aug 7, 2016 · The problem is my value doesn't have a fixed length. – Sep 27, 2016 · if the 21st character is a space, return the first 20 characters; if the 21st character is not a space, but there is a space among the first 20 characters, then chop off the first 20 characters, and then find the "last" space and delete it and everything after it. FROM @table. The color codes in this case would be 001, 0165, M2235, and 001. Firstly, let me say that your @UserComment variable is not long enough to contain the text you're putting into it. csv I only want what is after the last backslash i. Or an antipattern can be achieved by using the LIKE operator. LEN gives you the length of the string, then subtract 1 to get the previous char: SELECT SUBSTRING(Code, LEN(Code)-1,1) answered Oct 20, 2014 at 11:36. Here are some examples of these key values: R50470B50469. My input string is : '44345434595-E535-12349-5273-202003-16785' and I want to extract the string from 4th instance of hyphen to 5th instance of hyphen and my desired result is : 202003 Wrote 2 functions, 1 to return LastIndexOf for the selected character. Mar 30, 2021 · If you want the value from the second character onward, I would suggest stuff(): select stuff(str, 1, 1, '') If you specifically want to remove all characters up to the first occurrence of a character, such as 'x', then: select stuff(str, 1, charindex('x', str), '') If you want to do this conditionally -- so the string is returned even when 'x Jul 6, 2016 · SUBSTR ( columnName, LOCATE ( '123', columnName ) + 3 ) The reason for the "+ 3" is that we want to start searching three characters past the beginning of the '123'. 67895-xyz. What I need to do is split this value into 2 columns 32-HC-100-10001-G03P2-N and 1 - the numbers after last -don't important . You do this by subtracting the index from the column length then adding 1: LEN(email) - CHARINDEX('@', email) + 1. 117k 12 223 229. So output in table like, Jan 29, 2013 · Ask questions, find answers and collaborate at work with Stack Overflow for Teams. If you are going to search large volumes of data this way, there is a way to recover use of indexes. 12345-abc. Here are four examples: ABC123-001. a,b,c returns b,c. S-XYZ999-M2235. Use RIGHT w/ RTRIM (to avoid complications with a fixed-length column), and LEFT coupled with LEN (to only grab what you need, exempt of the last 3 characters). The second argument is the starting character, and the third argument is the ending character. Sep 25, 2013 · 35. I have used SUBSTRING([Line No#], 0, 21) but because of the length it Dec 4, 2015 · Try This Query: select substring(col,charindex('-',col)+1,len(col)-charindex('-',col)) from #Your_table. SET @charCount = @charCount - 1 --decrement charCount for each added char. mdf By searching for the location of the last occurrence of the delimiter '\' we can easily strip off just the filename using the RIGHT function. If the whole string is at most 20 characters, it should be returned as is. If there is no fixed pattern to the behaviour of your data, there is no fixed SQL query that can parse it. Doe USA-D. Note that the WHERE clause skips updating rows in which there is no semicolon. My current results are Dec 10, 2018 · With a combination of position and substring functions. 4-G-100-10029-F23S-S-2-1001 should be split into 4-G-100-10029-F23S-S and 2. select substr(col, 2) To Remove Last Character from a string. ', 1, 3) - 1) AS expected FROM table_name; If it may have fewer and you want the entire string in those cases then: Hi Everyone, I want to return the character (s) in a string directly after a dash (-) character. Is it possible in TSQL (sql server 2008)? Any other clues? Oct 12, 2017 · 0. 6. If using SQL Server: SELECT column1. ' Feb 13, 2012 · Use CHARINDEX. I would create this function: CREATE FUNCTION [dbo]. Mouse USA-P. Mar 1, 2021 · In the below SQL query, we use the [^] string operator. This example returns the first location of the string is in string This is a string, starting the search from position 4 (the fourth character). characters then you can use:. BCD45678-0165. Others may have a more elegant method, but have a play with this code: --DECLARE @String Oct 20, 2014 · Use SUBSTRING and LEN. end. SQL Substring and Charindex. I have a field that contains a string that contains a full file path i. This solution gets all characters/words after the keyword. Create a computed column that is the string in reverse order. In SQL Server, you can use SUBSTRING function, but it does not allow you to specify a negative start position, and the substring length must be specified . Feb 4, 2015 · Essentially looking the pattern &id=% and extract string after that till end of the line. SELECT @strToChange. And since we have a fixed delimiter we don't need the magic of regular expressions. You could do it using SUBSTRING() function: UPDATE table SET column = SUBSTRING(column, 0, LEN(column) + 1 - N) Removes the last N characters from every row in the column. Raj Baral. 4. Others may have a more elegant method, but have a play with this code: --DECLARE @String Nov 9, 2018 · INSTR ( string, substring [, start_position [, th_appearance ] ] ) ref. Share. Substantially faster than functions using regular expression matching. Aug 13, 2020 · The SUBSTRING function has the following syntax: SUBSTRING ( expression ,start , length ) . First, to split a string with SQL Server just after a certain character, use the three following built-in text functions: SUBSTRING to trim a text by indicating the start and length to be trimmed. ' if it does not contain a number. length); Nov 26, 2019 · As I mentioned in the comments: "The only alternative approach, I can think of, would be to use a string splinter which numbers the parts (e. W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Sep 28, 2017 · for ms-sql use SUBSTRING – Aaron. asad ullah. Panther. SUBSTR ( string, start_position [, length ] ) ref. The SUBSTRING function accepts three arguments: The source_string is the string from which you want to extract the substring. Split a string after a character using 3 standard T-SQL functions. You then index that column and look for WHERE LEFT(reversed,3 Oct 21, 2013 · I have (+1) because I actually need the string position after the last "," . sql-server. I want all in one statement using the update function. Sep 15, 2015 · . Maybe it will be useful to someone. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more. RETURN (LEN(@source)) - CHARINDEX(@pattern, REVERSE(@source)) and 1 to return a string before this LastIndexOf. ', -1) FROM test_table this will match the string from the right to the first occurance of '. Source – Nov 12, 2019 · I am trying to extract everything from my list of strings after the last underscore, after MOB_ in big query. This question has a database specific answer. SQL. \\Server\Folder1\Folder2\Folder3\File21. LEFT(STRING, LEN(STRING) - CHARINDEX('-', REVERSE(STRING))) STRIPPED_STRING. sql-server-2016. Oct 29, 2013 · In SQL Server 2008, I need to drop the last two characters from a series of item numbers in our database. B17699C88C68AM. ', [Name] + '. Sep 14, 2018 · It takes three arguments. Copy. --- EDIT -----As an example: This is an e[x]ample string. ') - 1 ) AS Name. Edit: I updated the example to show that there could be multiple dots in one string. If start is less than 1, the returned expression will begin at the first character that is specified in expression. ' (from the right) this will match string after second occurance of '. SELECT CHARINDEX('is', 'This is a string', 4); Here is the result set. Oct 22, 2019 · The SUBSTR and INSTR functions can be combined to get you the numeric code. It finds out the position of the character without an alphabet, number or space. Either you need to supply every possible format of data (so that we can infer the rules), or you need to describe the rules and we can translate them into SQL. i tried this . edited Apr 25, 2018 at 18:16. Oct 20, 2014 at 11:47. select substr(col,1, length(col)-1 Nov 24, 2020 · I want split string from '-' then show output into two columns,In First Column getting string before '-' like 'INDORE' from 'INDORE - Madhya Pradesh<56>' string & second column getting string after '-' and also remove charter after '<'this like Madhya Pradesh from 'INDORE - Madhya Pradesh<56>'. If the 50th character falls on the x in example, the code above will give me: Oct 7, 2020 · Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand Apr 16, 2017 · Im using a sql server 2014, when i execute the query it returns SUBSTRING_INDEX is not a recognized built-in function name. Any help would be appreciated I find it easier to reverse the string and look for the first space instead, and then reverse it back. g. 5. Oracle: -- Get first 3 characters SELECT SUBSTR ('New York', 1, 3) FROM dual; # New -- Get last 4 characters (negative start position) SELECT SUBSTR ('New York',-4) FROM dual; # York. This example extracts a substring with the length of 6, starting from the fifth character, in the 'SQL Server SUBSTRING' string. From the above string i want to print the substring value based on the position of slash occourence. This time, you get the CHARINDEX of the last (reverse the string) -, and subtract that from the length of the whole string. Jun 23, 2022 at 18:05. Thanks so much new to this and this problem has been bugging me for hours!! – BenYeomans. Using stored procedures or functions will fail because you want BB10-1_X to be a single string. May 4, 2018 · One solution could be: SUBSTRING(Serial, 18, 38) And it always return the substring from 18 to the end of the string even if the string doesn't have a length of 38. not all the numbers are the same format and i only need to drop characters from certain ones. Example Get your own SQL Server. all it remain to do is running a SUBSTR on my initial string FROM the calculated position. Feb 19, 2020 · Using SQL Server 2014. Apr 10, 2014 · This would work, I kept your inner substring which got you part way and I added the stripping of the dot. if there's ever a situation where the length is <= 3, then you're probably going to have to use a CASE Use split_part(): SELECT split_part('first:last', ':', 1) AS first_part. com I want to replace the string before @ with test. JOIN STRING_SPLIT('1,2,3',',') ON value = ProductId; The preceding STRING_SPLIT usage is a replacement for a common antipattern. DelimitedSplit8K_LEAD), and then select the first row based on item number descending. See example below: STRING: Topshop_AW19_Pro_MOB_competitors(mid price point)custom_affinity DESIRED OUTPUT: competitors(mid price point)custom_affinity May 27, 2010 · Get substring in SQL Server. Moreover, we can use the function to pinpoint the last occurrence of a char or substring in an SQL Sep 4, 2014 · I need it to sort the entire string, but on the last name. -- when the length is less than 50, or the character at position 50 is part of the last word, return the entire string. Sep 7, 2017 · 2. But how can i replace the underscore with blank. Hot Network Questions Cubic splines in Cox model I find it easier to reverse the string and look for the first space instead, and then reverse it back. there are lot of these out there. csv So in the world of SQL I would use: Select RIGHT([FileName],charindex('\',reverse([FileName]),1)-1) as FileNameNew from mytable Nov 9, 2018 · INSTR ( string, substring [, start_position [, th_appearance ] ] ) ref. Regular expressions are a great way to do this sort of thing. Explore Teams Create a free Team Jan 20, 2016 · The actual code will depend on whether you need the full prefix or the last slash. substring(val,position('-' in val)+1,8) To reformat in the hyphenated format, use to_char, after casting the substring to date. I've a task to print substring from a string based on the occurence of slash '/' position in a string . Mar 4, 2022 · I would like to remove a sub string after the last dot '. A) Using SUBSTRING() function with literal strings. Jun 22, 2023 · I want a SELECT statement that creates a new column where if a field called &quot;string&quot; ends with the letter A, B, or F it gets the value &quot;Ok&quot; otherwise it gets the value &quot;No& Apr 27, 2024 · LEFT(field_name, number of characters to extract FROM THE LEFT) Suppose that you created a table in SQL Server (called table_1) that includes the following 3 strings: identifier. Such an antipattern can involve the creation of a dynamic SQL string in the application layer or in Transact-SQL. Double substring. Extract 3 characters from a string, starting in position 1: SELECT SUBSTRING ('SQL Tutorial', 1, 3) AS ExtractString; Try it Yourself ». SELECT SUBSTRING([String],CHARINDEX('_',[String],(CHARINDEX('_',[String])+1))+1,100) Apr 24, 2019 · In other words, I would like to drop the dash -and numbers after the dash - This is the query I have tried so far: SELECT ID, AREA_DESC ,SUBSTRING(AREA_DESC,0,CHARINDEX('-', AREA_DESC)) as area FROM CARM Feb 14, 2014 · The general idea is to split out all of the characters in the string, determine the position of the delimiters, then obtain substrings relative to the delimiters. SELECT SUBSTRING (YourField, INSTR (Keyword,YourField) + LENGTH (Keyword), LENGTH (YourField)) for the mysql folks out there. What I am wanting to get out of the string, is all the numbers that occur after the character 'B' but before any other letter character if it exists such as 'C'. FROM myTable. If there are two last names that are identical, I would like for it to take the initial of the first name into account. 45678-mmm. com test@yahoo. , RIGHT(column2,CHARINDEX('-',REVERSE(column2))-1) as extracted. Here is the common approach, when working with SQL table: SELECT REVERSE (( SELECT TOP 1 VALUE FROM STRING_SPLIT(REVERSE(mySearchString), '/') )) AS myLastValue FROM myTable Share Feb 24, 2020 · I have a string where i need to extract the number before characters gsm . – user3127287 Apr 16, 2017 at 9:58 Mar 12, 2024 · 1. rchacko. Nov 30, 2017 · 9. Sep 20, 2012 · For Oracle SQL, SUBSTR(column_name, -# of characters requested) will extract last four characters for a given query. course; edited Aug 9, 2023 at 13:43. Interestingly, this function comes in handy to find a particular char or word in a string. SQL Jun 22, 2017 · Use SUBSTRING AND CHARINDEX to get last complete word in field. Result: test@yahoo. If you use this split often. Feb 19, 2016 · If you want to chop off everything after the last - instead (regardless of whether it's second or not): SELECT. fg zu ns sm bk hs pq sd aw bb