sql server - How to change sentence with a common pattern in SQL -
alexa, thank visiting chicago! hope come soon!
katana, thank visiting dallas! hope come soon!
siri, thank visiting new york city! hope come soon!
bixby, thank visiting seattle! hope come soon!
assuming these values in column on arbitrary table, how write sql query that'll replace of above "first name, thank visiting los angeles! hope come soon!"
although these 4 rows, i'm working on 500 need edited.
i'm using t-sql/ssms.
using stuff easiest way:
create , populate sample table (please save step in future questions)
declare @sampledata table ( sentence varchar(100) ) insert @sampledata values ('alexa, thank visiting chicago! hope come soon!'), ('katana, thank visiting dallas! hope come soon!'), ('siri, thank visiting new york city! hope come soon!'), ('bixby, thank visiting seattle! hope come soon!')
the update statement:
update @sampledata set sentence = stuff(sentence, charindex(',', sentence), len(sentence), ', thank visiting los angeles! hope come soon!')
test:
select * @sampledata sentence '%, thank visiting %! hope come soon!'
results:
sentence alexa, thank visiting los angeles! hope come soon! katana, thank visiting los angeles! hope come soon! siri, thank visiting los angeles! hope come soon! bixby, thank visiting los angeles! hope come soon!
Comments
Post a Comment