Solved

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

Posted on 2004-04-06
5
23,176 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
5 Comments
 
LVL 13

Accepted Solution

by:
alpmoon earned 25 total points
Comment Utility
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
Comment Utility
Yes. Combination of stuff, charindex works.

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

Author Comment

by:diarmaid
Comment Utility
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
Comment Utility
please try str_replace command. this is replace equivalent in sybase.
0
 

Expert Comment

by:dougsur
Comment Utility
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sybase ASE 15.7 do not know datepart function 2 1,184
ORCA Powerbuilder import 7 1,026
compare Sybase and MSSQL server 18 732
MS SQL Linked server 3 117
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now