Solved

SQL EXCEPT not recognizing differences in capitalization

Posted on 2014-10-17
4
101 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
Comment Utility
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
Comment Utility
Excellent, that was it!  Thanks!
0
 

Author Closing Comment

by:qinformation
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 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