?
Solved

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

Posted on 2004-04-06
5
Medium Priority
?
23,195 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 100 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 100 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
The Summer 2017 Scholarship Winners have been announced!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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