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.
| 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)ASBEGINDECLARE @Output nvarchar(200)WHILE LEN(@Input) > 0BEGIN 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 = '' ENDENDRETURN SUBSTRING(@Output,1,LEN(@Output))ENDSELECT [dbo].[udf_ReverseSequenceOrder]('SQL TEAM',' ')--Chandu |
 |
|
|
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 = AddressLine2update users set AddressLine2 = (SELECT [dbo].[udf_ReverseSequenceOrder](AddressLine2)) where IsPatient = 1getting errors help me out!!!P.V.P.MOhan |
 |
|
|
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 = AddressLine2update users set AddressLine2 = (SELECT [dbo].[udf_ReverseSequenceOrder](AddressLine2)) where IsPatient = 1getting errors help me out!!!P.V.P.MOhan
update users set AddressLine2 = [dbo].[udf_ReverseSequenceOrder](AddressLine2, ' ') where IsPatient = 1--Chandu |
 |
|
|
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 muchP.V.P.MOhan |
 |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-10-19 : 08:43:46
|
You are Welcome --Chandu |
 |
|
|
|
|
|
|
|