none
How to update an HTML element in a string RRS feed

  • Question

  • Dear all,

    I need to change a HTML element from a single string database field

    In the whole string return I need to replace all string which is inside <BaseUrl>string to be replace</BaseUrl>

    what is the best way to do ?

    regards

    Monday, October 7, 2019 7:56 AM

Answers

  • Hi wakefun,

    Could you please share us your table structure (CREATE TABLE …) and some sample data(INSERT INTO …) along with your expected result? So that we’ll get a right direction and make some test.

    Or please try it.

    replace(@xml,'<BaseUrl>A</BaseUrl>','<BaseUrl>string to be replace</BaseUrl>')

    Best Regards,

    Rachel 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by wakefun Tuesday, October 8, 2019 1:53 PM
    Tuesday, October 8, 2019 7:02 AM

All replies

  • Can you show and example?

    SELECT  REPLACE(@str,'<BaseUrl>','</BaseUrl>' ) 


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Monday, October 7, 2019 8:26 AM
    Answerer
  • Hi wakefun,

    We can use REPLACE or STUFF or SUBSTRING Function based on inputs.

    Can you attach any real example and expected output of it, to proceed in the correct direction.

    Please mark this as answer if it solved your issue. 
    Please vote this as helpful if it helps to solve your issue. 

    Thanks,
    Arulmouzhi


    Monday, October 7, 2019 8:43 AM
  • what is the best way to do ?

    Using a HTML parser or regex in the front-end.

    Monday, October 7, 2019 9:01 AM
  • If you never need the original Url, or can save it separately, then do not store it inside this field. Keep just a placeholder or an empty element like this: “<BaseUrl/>”. Then you can use a simple REPLACE(myfield, ‘<BaseUrl/>’, ‘<BaseUrl>‘ + newUrl + ‘</BaseUrl>’), which can be also done in non-SQL modules.

    If it is a valid XML (XHTML), then probably you can also use the XML features.

    • Edited by Viorel_MVP Monday, October 7, 2019 11:51 AM
    Monday, October 7, 2019 9:17 AM
  • Hi wakefun,

    Could you please share us your table structure (CREATE TABLE …) and some sample data(INSERT INTO …) along with your expected result? So that we’ll get a right direction and make some test.

    Or please try it.

    replace(@xml,'<BaseUrl>A</BaseUrl>','<BaseUrl>string to be replace</BaseUrl>')

    Best Regards,

    Rachel 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by wakefun Tuesday, October 8, 2019 1:53 PM
    Tuesday, October 8, 2019 7:02 AM