I wholeheartedly agree with @OriginalGriff and if anyone tells you different they're wrong :laugh:
However, I note your comment that you appear to have no choice so here is an alternative approach using REPLACE
declare @Test varchar(125) = '25/26*34+21+15'
select '[' + replace(replace(replace(replace(@Test, '+',']+['), '-',']-['),'*',']*['),'/',']/[') + ']'
Points to note:
- I have only used
+
,
-
,
*
and
/
- you will have to extend the principle for any other characters you want to use
- Be sure to read the documentation at
REPLACE (Transact-SQL) | Microsoft Docs[
^]
- Spot the
[
and
]
added at either end and consider what will happen if your string begins or ends with any of the characters you are replacing
- Try to find a way to do this in your presentation layer