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
Spanning-tree Cost to block uplink to core Switches.
Pervasive SQL 9.5 - odbc SELECT Query - DATE = '0000-00-00'
Constant BSOD on boot/install of Windows 7
Dynamically Change .XSD File Location in Crystal Reports Using ASP.NET 2.0
Static route to website in Squid
'guid' is null or not an object in Jquery
Move DC role from Exchange Server
error while installing Exchang 2010
Having a problem seeing USB devices after installing libusb - NO KEYBOARD OR MOUSE !!
can ping by ip, and by name, but not browse