June 9, 2010 at 2:39 am
With out using UDF
Suppose i have a string like TEST, then i just want to output string as
TES.
Need Help!
Thanks in advance
Ritesh Bhatt
June 9, 2010 at 2:58 am
Got a question bro, do we have to retain only the first occurence of a duplicated character in that string?
June 9, 2010 at 3:10 am
This should do what you want: -
DECLARE @old_string VARCHAR(35)
DECLARE @count INT
DECLARE @new_string VARCHAR(35)
SET @count=1
SET @old_string = 'test'
WHILE ( @count <= 35 )
BEGIN
IF ( @new_string IS NULL )
BEGIN
SET @new_string=''
END
SET @new_string=@new_string + Substring(@old_string, 1, 1)
SET @old_string=REPLACE(@old_string, Substring(@old_string, 1, 1), '')
SET @count=@count + 1
END
SELECT @new_string
June 9, 2010 at 4:08 am
Yes, Very true
TESTRBTEST
Then we need only
TESRB
🙂
June 9, 2010 at 4:11 am
Glad I could help :w00t:
June 9, 2010 at 4:43 am
Here's another way
DECLARE @s-2 VARCHAR(100)
SET @s-2='TESTRBTEST'
SELECT @s-2 = CASE WHEN CHARINDEX(SUBSTRING(@s,Number,1),@s) BETWEEN 1 AND Number-1 THEN STUFF(@s,Number,1,'') ELSE @s-2 END
FROM master.dbo.spt_values
WHERE Number BETWEEN 2 AND LEN(@s) AND type='P'
ORDER BY Number DESC
SELECT @s-2
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537June 9, 2010 at 5:12 am
Thnx dude it works 🙂
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply