Stanton_Roux
asked on
Split string in SQL Stored procedures
Hi There
I have a string that comes through as follows
A24+B34.56* or sometimes comes through like this A24 or B34.78
I would like to check the string in my stored procedure.
If there is a + sign in the string I want to split the string into 2 values using the plus sign as the delimiter.
If there is no plus sign I would just like to use the value as it comes.
Thanks
Stanton
I have a string that comes through as follows
A24+B34.56* or sometimes comes through like this A24 or B34.78
I would like to check the string in my stored procedure.
If there is a + sign in the string I want to split the string into 2 values using the plus sign as the delimiter.
If there is no plus sign I would just like to use the value as it comes.
Thanks
Stanton
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops still busy typing and angell has already given answer Sorry
SELECT
CASE
WHEN CHARINDEX( '+', myField) > 0
THEN
SUBSTRING( myField, 1, CHARINDEX( '+', myField ) -1 )
ELSE MYFIELD
END AS LEFT_FIELD,
CASE
WHEN CHARINDEX( '+', myField ) > 0
THEN
SUBSTRING( myField, CHARINDEX( '+', myField ) +1 , LEN(myField) -CHARINDEX( '+', myField ) - 1 )
ELSE
myField
END AS RIGHT_FIELD,
FROM myTable