Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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