[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 23206
  • Last Modified:

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

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
diarmaid
Asked:
diarmaid
2 Solutions
 
alpmoonCommented:
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
 
namasi_navaretnamCommented:
Yes. Combination of stuff, charindex works.

See example:
http://www.experts-exchange.com/Databases/Q_20847199.html
0
 
diarmaidAuthor Commented:
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
 
sandhiyaaCommented:
please try str_replace command. this is replace equivalent in sybase.
0
 
dougsurCommented:
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now