Solved

Easy - Whats the equivalent of SQL Server REPLACE function in Sybase?

Posted on 2004-04-06
5
23,190 Views
Last Modified: 2011-04-14
There doesnt appear to be a REPLACE(str1,str2,str3) function in sybase. There must be an equivalent function to replace a string of chars (str2) with a new string of chars (str3) in a string (str1)

Whats it called and whats the format?
0
Comment
Question by:diarmaid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Accepted Solution

by:
alpmoon earned 25 total points
ID: 10770984
You can use stuff (there are more details in reference guide):

Returns the string formed by deleting a specified number of characters from one string and replacing them with another string.

Syntax :
stuff(char_expr1 | uchar_expr1, start, length, char_expr2 | uchar_expr2)

Parameters :
char_expr1
is a character-type column name, variable, or constant expression of char, varchar, nchar or nvarchar type.
uchar_expr1
is a character-type column name, variable, or constant expression of unichar or univarchar type.
start
specifies the character position at which to begin deleting characters.
length
specifies the number of characters to delete.
char_expr2
is another character-type column name, variable, or constant expression of char, varchar, nchar or nvarchar type.
uchar_expr2
is another character-type column name, variable, or constant expression of unichar or univarchar type.

Examples :
Example  1
select stuff("abc", 2, 3, "xyz")
----
axyz

Example  2
select stuff("abcdef", 2, 3, null)
go
---
aef

Example  3
select stuff("abcdef", 2, 3, "")
----
a ef
0
 
LVL 15

Assisted Solution

by:namasi_navaretnam
namasi_navaretnam earned 25 total points
ID: 10771115
Yes. Combination of stuff, charindex works.

See example:
http://www.experts-exchange.com/Databases/Q_20847199.html
0
 
LVL 2

Author Comment

by:diarmaid
ID: 10773276
thanks to you both,
Its a definate downfall of sybase that it doesnt provide such a basic function that most people take for granted !!!
I had figured out about using stuff with charindex but was convinced that Sybase would have a replace function, only it was named something else, People can give out about MS but they come up with the goods !!!
0
 
LVL 1

Expert Comment

by:sandhiyaa
ID: 20175853
please try str_replace command. this is replace equivalent in sybase.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's how to start interacting with our community through Post.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question