New column value baed on xml string column tag

kasim mohamed 581 Reputation points
2022-09-13T08:10:52.857+00:00

Hi

I have table with nvarchar(max) column where i stored xml string.
in that xml column some xml column having <Attachment> tag some not.

what am expecting is, i need one new column as 'Attachment'. if that xml string column having <Attachment> tag then it should be 'YES' else 'No'

240415-image.png

Thanks in Advance

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. LiHongMSFT-4306 31,616 Reputation points
    2022-09-13T08:20:26.94+00:00

    Hi @kasim mohamed
    Try this:

    SELECT File_xml,CASE WHEN PATINDEX('%Attachment%',File_xml)>0 THEN 'YES' ELSE 'NO' END AS Attachment  
    FROM xml_table  
    

    Best regards,
    LiHong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.