In the recent past I have seen the best interaction and learning happens when we all get into a puzzle and challenge mode. And that just gets the creative juice in our minds and some really innovative solutions are given. So this blog is written like a nice trivia solution and I would love to hear from you on potential alternate solutions to this as you read the simplified solution.
There are many situations where a developer needs to do a lot of string manipulation using T-SQL. There are many things which ideally should be done via SQLCLR.
One of my blog reader posted a comment recently
I want to get only integer part in string. for example, string contain ab123ce234fe means i want only integer part like 123234. how can i get?
I gave him below suggestion.
SET NOCOUNT ON
DECLARE @loop INT
DECLARE @str VARCHAR(8000)
SELECT @str = 'ab123ce234fe'
SET @loop = 0
WHILE @loop < 26
SET @str = REPLACE(@str, CHAR(65 + @loop), '')
SET @loop = @loop + 1
Do you think there is a better way to achieve that? Please write it in comments section. It is going to be a great learning opportunity for all.
Reference: Pinal Dave (https://blog.sqlauthority.com)