Skip to content

Instantly share code, notes, and snippets.

@oscarandreu
Created February 17, 2016 16:12
Show Gist options
  • Select an option

  • Save oscarandreu/e9e8730f3360e309b8ca to your computer and use it in GitHub Desktop.

Select an option

Save oscarandreu/e9e8730f3360e309b8ca to your computer and use it in GitHub Desktop.
Replace part of a field and update the row
;WITH CTE AS
(
SELECT top 2
[Lab_ID] id
,replace(Lab_HtmlDefinition, 'data-pdnbind="src: resources/V1/products/{ean}_04;"', '') html
,CASE WHEN Lab_HtmlDefinition <> replace(Lab_HtmlDefinition, 'data-pdnbind="src: resources/V1/products/{ean}_04;"', '') THEN 1 ELSE 0 END WasReplaced
FROM [dbo].[Lab_Pricelabels]
WHERE --lab_customerId = 180211 and
Lab_ID = 560589
)
--select count(*) from cte where Lab_HtmlDefinition like '%FOOOOOOOOOOOOOOOOOOOOOOOOOOF%'
--select * from cte
update lbl
set lab_htmldefinition = html
FROM dbo.lab_pricelabels lbl inner join cte ON id = Lab_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment