# SQL Query issue wrong result

**URL:** <https://forum.inductiveautomation.com/t/sql-query-issue-wrong-result/42324>\
**Category:** General Discussion\
**Tags:** database\
**Created:** [January 15, 2021, 10:32pm UTC](https://forum.inductiveautomation.com/t/sql-query-issue-wrong-result/42324 "2021-01-15T22:32:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [January 15, 2021, 10:32pm UTC](https://forum.inductiveautomation.com/t/sql-query-issue-wrong-result/42324/1 "2021-01-15T22:32:14Z")

</div>

Hi  
I faced a strange issue in one of SQL query. is there any explanation of it?  
I had a query as below as per row data there’s a reason “F1784: ROB Collecting centering not closed 1LK E2\_E3”  
but in result reason appeared as “F1784: ROB ?ollecting centering not closed 1LK E2\_E3”  
?Collecting instead of Collecting …

```auto
declare @top10 table (Duration real, Reason varchar(400) )
insert into @top10 (Duration , Reason ) 
select 
duration/60.0 as Duration,
CASE WHEN spare2 <> 'NULL' THEN spare2 End AS [Reason] --util_reas.reas_desc else END AS--  

from util_log WITH (NOLOCK)
	--INNER JOIN util_reas util_reas ON ul.reas_cd = util_reas.reas_cd

where ent_id = 147 and 
event_time_local >= '2021-01-15 15:09:00.000' and event_time_local <= '2021-01-15 19:41:00.000'
and ((state_cd = 0 ) or (spare4 = 0 ) or 
(state_cd = 11 ) or (spare4 = 11 ) or
(state_cd = 12 ) or (spare4 = 12 ) or
(state_cd = 13 ) or (spare4 = 13 ) or
(state_cd = 17 ) or (spare4 = 17 ) or
(state_cd = 18 ) or (spare4 = 18 ) or
(state_cd = 19 ) or (spare4 = 19 ) )
--and util_reas.reas_desc <> 'PLC Communication Failed'  
and spare4 <> 6 order by log_id desc

 select Reason, sum(Duration) as Duration from @top10 group by Reason order by Duration desc

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 16, 2021, 11:04am UTC](https://forum.inductiveautomation.com/t/sql-query-issue-wrong-result/42324/2 "2021-01-16T11:04:25Z")

</div>

Sounds like your data has special characters in it that aren’t recognised. Try cleaning the result

---

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [January 16, 2021, 12:30pm UTC](https://forum.inductiveautomation.com/t/sql-query-issue-wrong-result/42324/3 "2021-01-16T12:30:19Z")

</div>

Solved change varchar to nvarchar
