Solved

SQL EXCEPT not recognizing differences in capitalization

Posted on 2014-10-17
4
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

749 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