SQL_Enthusiast (5/7/2013)
I have a value that is '0111~Group Name' in a column called GROUP_NUM in a table called TEMP_TABLEI need to know how to select everything LEFT of the ~ and then RIGHT of the ~, but not show the TILDE. SELECT LEFT VALUE, RIGHT VALUE FROM TEMP_TABLE...
I tried..., but it failed. Not enough arguements. Thoughts, suggestions, references?
SELECT LTRIM(RTRIM(SUBSTRING([tt].[GROUP_NUM], CHARINDEX('~')))) FROM [dbo].[TEMP_TABLE] AS tt
You really need to read the Manual. 🙂
Which is BOL (Books On Line), which is "Help" (F1).
SUBSTRING takes 3 arguements - String, Position From, Position To.
In your case - SUBSTRING([tt].[GROUP_NUM], 1, CHARINDEX('~'))
For the RIGHT part use REVERSE function:
Reverse the sourse string ([tt].[GROUP_NUM]), do the SUBSTRING thing and then reverse the output.
_____________
Code for TallyGenerator