Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have use this query to get data.
SELECT t1.HId,
commands=STUFF   
(   
     (   
       SELECT DISTINCT ',' + t2.commands  
       FROM history_detail t2
       WHERE  t1.HId = t2.History_HID    
       FOR XML PATH('')   
     ),1,1,''   
)   
FROM history t1,  history_detail t2  
GROUP BY HId 


but out put is this of commands columns
Send("this is your first testcase")

,Sleep(3000)

`�xD;`
,WinActive("notepad")
`�xD;`
,WinClose("notepad")
`�xD;`
,WinWaitActive("notepad")`�xD;`


i wnat to remove `�xD;` from data which is coming together with it.

What I have tried:

i have try but the extra data is not removed
Posted
Updated 4-Apr-18 7:00am
v5

You need to look at your data: specifically at what is stored in your history_detail.commands column.
It looks like whatever put the data in there has added some rubbish to teh end - you may be able to remove it using the SQL CHARINDEX and SUBSTRING functions but you need to find out exactly what it is first.
CHARINDEX (Transact-SQL) | Microsoft Docs[^]
SQL Server SUBSTRING() Function[^]

Me? I'd look at the code that inserted the data, and see if I could either prevent the corruption, or add it as a different column.
 
Share this answer
 
You're getting XML-encoded output. Change the query to:
SQL
SELECT 
    t1.HId,
    commands = STUFF   
    (   
        (   
            SELECT DISTINCT ',' + t2.commands  
            FROM history_detail t2
            WHERE  t1.HId = t2.History_HID    
            FOR XML PATH(''), TYPE
        ).value('.', 'varchar(max)'), 1, 1, ''   
    )   
FROM 
    history t1
;

  • Add ,TYPE after PATH('');
  • Add .value('.', 'varchar(max)') after the nested query;

There's no need to include history_detail in the outer query; removing it will also remove the need for the GROUP BY clause.

Concatenating Row Values in Transact-SQL - Simple Talk[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900