Link to home
Start Free TrialLog in
Avatar of enrique_aeo
enrique_aeo

asked on

sql server 2012: REPLACE, REPLICATE

Please experts,

I undertstand REPLACE, REPLICATE
Please share a real scenario using REPLACE, REPLICATE
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
declare @val varchar(100), @val1 varchar(100), @val2 varchar(100)
set @val = 'I am feeling lucky today'
set @val1 = REPLACE(@val, 'lucky', 'fortunate')
print @val1 --It would print "I am feeling fortunate today"

set @val2 = REPLICATE('!', 3) + @val + REPLICATE('!', 3)
print @val2 --It would print "!!!I am feeling lucky today!!!"