Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Strange behavior of select query; it doesnot return rows whereas table has data

$
0
0

the following select query returns:
Select * from sales where CustLastname ='Smith'

Dave    Smith
John    Smith
Marry    Smith
........ Lets say large out put of million rows. The output has other columns too, not specifying them for simplicity.



The following select query on the same table doesnot return any output:


Select * from sales where CustFirstname ='Dave'
---- Now rows returned -----

Whereas when I modify the query a little bit like:
Select * from sales where CustFirstname ='Dave' + CHAR(0)

It returns the rows
Dave    Smith
Dave    Wells
....


Other facts about the issue:
1.    Initially, I thought this is a corruption issue so performed a dbcc with and without dataloss
2.    I even restored the database from production to the QA environment and still the same issue.
3.    This behaviour is only with the column CustFirstname, queries on other columns work perfectly.
4.    Tried to execute the query with sqlcmd with output to a file, same issue.
5.    the table has a single collation. This columns has the same collation as the other columns in the table.
6.    I tried to copy the output of the table in to a new table using select * into but the new table also has the same issue.
7.    I tried to even drop the clustered index on the table which was coming as the only index being scanned for the output of the query.

I have already spend over 5-6 overs to understand what can be the reason behing this issue but no success till now.
I feel I can fix this issue by creating a new table first and then use the insert into caluse to copy all data but I need to understand what is the root cause of this issue.



Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>