Microsoft
Software
Hardware
Network
Question : How to just grab the specifc text from T-SQL?
Hi, I'm writing a query and need to just grab a section of the string. Can anyone help?
For example: SELECT ACCOUNTNAME FROM ACCOUNT
Return results sample: 10294 - Mayberry
I need the return result to be just "Mayberry". I thought of using substring, but it appears that it can only use a set number of values for starting and ending point. I just need it to grab the account name AFTER the '-' symbol, that's what gets me.
Thanks!
Answer : How to just grab the specifc text from T-SQL?
Use CHARINDEX to find the starting point for the SUBSTRING function:
SELECT SUBSTRING(AccountName, CHARINDEX('-', AccountName) + 1, (LEN(AccountName) - (CHARINDEX('-', AccountName) + 1)) AS DelimitedAcctName FROM ACCOUNT
hth
valkyrie_nc
Random Solutions
AJAX post returning 500 Internal Server Error on Live Server
VMware, vSphere Virtual Machine and Disk Errors "invalid disk type 7" and "cannot detect guest operating system type"
Direct X 10.1 vs Direct X 11, Windows XP SP3 vs Windows 7
mysql stored proc parameter
How to map external ip to internal subnet on a Cisco ASA
"Invalid Argument provided." Error when Generating PDFs in VB.NET Application via Crystal Reports Viewer
Will an AGP Video Card work in a PCI Express Slot?
HP Desktop memory
Bind List<List<string>> to Grid
Formula to split Names