sql2k
How could I use REPLACE (or something else like it) if I dont know what the
value or length to REPLACE is? I will always REPLACE with the same value,
so that parts not an issue.
declare @.Value varchar(128)
set @.Value = 'abc\123'
This time I want "abc\" to be replaced with "test$" so the result would be
"test&123".
but the next time:
declare @.Value varchar(128)
set @.Value = 'defghi\123'
This time I want "defghi\" to be replaced with "test$" so the result would
be "test&123".
TIA, ChrisRIf you want to replace everything up to the first '' character, use
STUFF or concatenation:
declare @.position int
set @.position = charindex('',@.Value)
if @.position > 0
set @.Value = 'test$' + substring(@.Value,@.position+1,128)
or instead of the SET statement above,
set @.Value = STUFF(@.Value,1,@.position,'test$')
Steve Kass
Drew University
ChrisR wrote:
>sql2k
>How could I use REPLACE (or something else like it) if I dont know what the
>value or length to REPLACE is? I will always REPLACE with the same value,
>so that parts not an issue.
>declare @.Value varchar(128)
>set @.Value = 'abc\123'
>This time I want "abc\" to be replaced with "test$" so the result would be
>"test&123".
>but the next time:
>declare @.Value varchar(128)
>set @.Value = 'defghi\123'
>This time I want "defghi\" to be replaced with "test$" so the result would
>be "test&123".
>
>TIA, ChrisR
>
>|||You wouldn't use REPLACE, you could say something like this:
SET @.value = 'defghi'+SUBSTRING(@.VALUE, CHARINDEX('', @.VALUE), 128)
"ChrisR" <noemail@.bla.com> wrote in message
news:OyYLBaYjFHA.1412@.TK2MSFTNGP09.phx.gbl...
> sql2k
> How could I use REPLACE (or something else like it) if I dont know what
> the value or length to REPLACE is? I will always REPLACE with the same
> value, so that parts not an issue.
> declare @.Value varchar(128)
> set @.Value = 'abc\123'
> This time I want "abc\" to be replaced with "test$" so the result would be
> "test&123".
> but the next time:
> declare @.Value varchar(128)
> set @.Value = 'defghi\123'
> This time I want "defghi\" to be replaced with "test$" so the result would
> be "test&123".
>
> TIA, ChrisR
>|||What exactly are you trying to achieve? If these replacements were to follow
a rule this would be much easier. Is the backslash character present in all
the strings?
ML
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment