locked
stuff cannot read all charecters RRS feed

  • Question

  • User-1634604574 posted

    i have this code stuff is not read character <> why?

    create table #TableJS (line_js varchar(max))
    
    declare @text varchar(max)='<xkjg>'
    
    
    insert into #TableJS select @text
    
    SELECT  STUFF((SELECT ',' + line_js
    
              FROM #TableJS r2
    
              FOR XML PATH('')), 1, 1, ''
    		  ) AS JS

    Wednesday, October 2, 2019 11:50 AM

All replies

  • User475983607 posted

    i have this code stuff is not read character <> why?

    The code works exactly as written.   The &lt; and &gt; are XML encoded characters for < and >.  This is expected given the code.

    Can you explain the problem you are trying to solve?   You are trying to insert JavaScript into a table column? 

    Wednesday, October 2, 2019 12:01 PM
  • User-1634604574 posted

    i want this result

    <xkjg>
    Wednesday, October 2, 2019 12:05 PM
  • User475983607 posted

    i want this result

    <xkjg>

    Then why are you using STUFF?  This is a very basic SELECT.

    SELECT line_js FROM #TableJS

    Keep in mind, the community cannot guess your design intentions.  You need to explain the general problem you are trying to solve.  I assume you started using STUFF because rendering the script in a web page caused the same encoding issue. 

    If you trust the JS Code, then there are openly published methods that will render the HTML without encoding.  The syntax depends on the framework you are using, Web Forms, MVC, ASP,NET Core.

    Wednesday, October 2, 2019 12:32 PM
  • User-719153870 posted

    Hi zhyanadil,

    SELECT  STUFF((SELECT ',' + line_js
    
              FROM #TableJS r2
    
              FOR XML PATH('')), 1, 1, ''
    		  ) AS JS

    This kind of statement is usually used to query multiple rows from SQL tables to a single row.

    However, in your current #TableJS there's only one row:<xkjg>, i believe this statement is not necessary.

    You will only need a simple select string as @mgebhard provided.

    For more information to understand about this statement and Stuff.

    Best Regard,

    Yang Shen

    Thursday, October 3, 2019 7:21 AM