none
SQL Sever Query RRS feed

  • Question

  • Hi,

    i am trying to retrive required data from the below string:

    {100012,100000,0,double,<tag><Attribute></Attribute><Source></Source><Name><![CDATA[NAD_C1_CL_DC_PWR_ELECT_A]]></Name><Map></Map><datatype>double</datatype></tag>}

    the above string gets stored in one of the column in database

    i want to display it as NAD_C1_CL_DC_PWR_ELECT_A 

    Also, the size of this string is not fixed it changes dynamicaly

    Could you please help how can we do this?

    Regards,

    Afshaan

    Wednesday, April 17, 2019 10:13 AM

All replies

  • Hi Mohammad Afshaan Shaikh

    I thinks following script help to you

    SELECT SUBSTRING(string, CHARINDEX('NAD_C1_CL_DC_PWR_ELECT_A', string), LEN(string) - CHARINDEX(REVERSE('NAD_C1_CL_DC_PWR_ELECT_A'), REVERSE(string)) - CHARINDEX('NAD_C1_CL_DC_PWR_ELECT_A', string) + 2)
    FROM(VALUES(
    '{100012,100000,0,double,<tag><Attribute></Attribute><Source></Source><Name><![CDATA[NAD_C1_CL_DC_PWR_ELECT_A]]></Name><Map></Map><datatype>double</datatype></tag>}'), 
    ('{100012,100000,0,double,<tag><Attribute></Attribute><Source></Source><Name><![CDATA[NAD_C1_CL_DC_PWR_ELECT_A')
                ) AS dt(string);

    Hope it can help you.

     

    Best Regards,

    Natig


    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. 

    Wednesday, April 17, 2019 11:03 AM
  • Hi,

    Thanks for your reply this string comes in one column which has a dynamic length 

    so this shall not work for me

    Could you please help

    Regards,

    Afshaan

    Wednesday, April 17, 2019 11:15 AM
  • Hi Mohammad,

     

    Unfortunately, the intercepted string you want doesn't have an explicit identifier to determine the start and end of the interception, so it's hard to have a method that works for you. You can only manually insert this line.

     

    Hope this could help you .

    Best regards,

    Dedmon Dai


    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

    Monday, April 22, 2019 1:33 AM