Solved

SQL EXCEPT not recognizing differences in capitalization

Posted on 2014-10-17
4
108 Views
Last Modified: 2014-10-17
I am comparing two tables to determine which rows have changed and should be included in a data interface.  Changes in capitalization are not being trapped by the EXCEPT clause. The following example does not return any rows when it should return the row from the left table because it is technically different.

Create table #temp3 (name varchar(max))
Create table #temp4 (name varchar(max))


insert into #temp3 Select 'Paul'
insert into #temp4 Select 'PAUL'

Select * from #temp3
EXCEPT
Select * from #temp4

Open in new window

0
Comment
Question by:qinformation
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40387582
The collation on each name column must be set to case sensitive, which since it wasn't explicitly declared in the CREATE TABLE #tmp statements I'm guessing it's taking the collation from the database default.  

To view, in SSMS go to the database and do a right-click:Properties, and eyeball the General tab, Collation property.  Looking at the letters in the second group from the right, _CI_ means case insensitive (i.e. Paul will = PAUL), _CS_ means case sensitive (Paul <> PAUL)
0
 

Author Comment

by:qinformation
ID: 40387596
Excellent, that was it!  Thanks!
0
 

Author Closing Comment

by:qinformation
ID: 40387597
Been doing this for years and years but never had to deal with collation until now.  Always learning!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40387603
Wait until you have to study for Microsoft exams, you learn all sorts of goofy cr*p you never had to deal with before.

Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now