Solved

SQL EXCEPT not recognizing differences in capitalization

Posted on 2014-10-17
4
106 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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…

910 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

19 Experts available now in Live!

Get 1:1 Help Now