Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to reverse the characters not getting any??

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2012-10-19 : 07:23:07
Hello all,

i have users table in that one i need to reverse characters like 'SQL TEAM' have to be 'TEAM SQL' i need to update lot of records at one go.I know reverse function cant able to find any solution????

P.V.P.MOhan

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-19 : 07:43:29
CREATE FUNCTION [dbo].[udf_ReverseSequenceOrder]
(
@Input nvarchar(200)
,@Delimiter nvarchar(5)
)

RETURNS nvarchar(200)
AS

BEGIN

DECLARE @Output nvarchar(200)

WHILE LEN(@Input) > 0
BEGIN
IF CHARINDEX(@Delimiter, @Input) > 0
BEGIN
SET @Output = SUBSTRING(@Input,0,CHARINDEX(@Delimiter, @Input)) + @Delimiter + ISNULL(@Output,'')
SET @Input = SUBSTRING(@Input,CHARINDEX(@Delimiter, @Input)+1,LEN(@Input))
END
ELSE
BEGIN
SET @Output = @Input + @Delimiter + ISNULL(@Output,'')
SET @Input = ''
END
END

RETURN SUBSTRING(@Output,1,LEN(@Output))
END

SELECT [dbo].[udf_ReverseSequenceOrder]('SQL TEAM',' ')

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2012-10-19 : 08:27:16
THanks man it is working fine but i need to update records by using this function i am not able to write query


declare @name varchar(200)
set @name = AddressLine2
update users set AddressLine2 = (SELECT [dbo].[udf_ReverseSequenceOrder](AddressLine2)) where IsPatient = 1

getting errors help me out!!!

P.V.P.MOhan
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-19 : 08:31:54
quote:
Originally posted by mohan123

THanks man it is working fine but i need to update records by using this function i am not able to write query


declare @name varchar(200)
set @name = AddressLine2
update users set AddressLine2 = (SELECT [dbo].[udf_ReverseSequenceOrder](AddressLine2)) where IsPatient = 1

getting errors help me out!!!

P.V.P.MOhan




update users set AddressLine2 = [dbo].[udf_ReverseSequenceOrder](AddressLine2, ' ') where IsPatient = 1

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2012-10-19 : 08:38:41
THanks man i am new to sql because of you people i am learning so much

P.V.P.MOhan
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-19 : 08:43:46
You are Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -