Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Easy order-of-operations question

Author  Topic 

ConradK
Posting Yak Master

140 Posts

Posted - 2009-11-17 : 13:12:26
I am new to SQL, and have no prior coding experiance. This may be a dumb question; but I am wondering about the order of operations in a replace function.

For example:

In a set of data with value ab can I

REPLACE(REPLACE(stringab, 'b', 'a'), 'aa', 'works')

and get "works" as a result?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-11-17 : 13:25:42
innermost to outermost is the order of operation

so REPLACE(REPLACE(stringab, 'b', 'a'), 'aa', 'works')

REPLACE(
REPLACE(stringab, 'b', 'a') -- do this 1st
, 'aa', 'works')
Go to Top of Page

ConradK
Posting Yak Master

140 Posts

Posted - 2009-11-17 : 13:39:10
cool, so it would replace 'b' with 'a', then have a data set of 'aa', and then replace the 'aa' with 'works' yeah?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-11-17 : 15:05:46
yep. ez to test too, try it out
Go to Top of Page

ConradK
Posting Yak Master

140 Posts

Posted - 2009-11-17 : 15:10:00
Yeah, the data I am working with is pretty massive, and I wanted to make sure I'm doing it right the first time. I will try it from now.

Thanks for your help guys!
Go to Top of Page
   

- Advertisement -