Solved

SEARCH in TEXT field type in CASE SENSITIVE MS SQL SERVER 2000 Database

Posted on 2004-08-17
7
988 Views
Last Modified: 2012-06-21
Hi friends,

I am having a problem with a simple select query which can be displayed as follows:

SELECT ID, NAME
FROM TABLE1
WHERE TABLE1.TEXTFIELD1 LIKE '%MySearchText%'

Since the Database is case sensitive I will have to use the UPPER function in the statement but the TEXT field type in the Database doesn't support this function.

Making database case insesitive in run time is not advisable since the database is shared in the network.

Is there anyone around who can help me?

0
Comment
Question by:juliusrai
[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
  • 3
  • 2
7 Comments
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11828604
Change the collation in the statement to an non case sensitive collation using the COLLATE function.

Tony
0
 

Author Comment

by:juliusrai
ID: 11829050
Thanks for participation tonyhowarth.

I got it how to do it.

the thing is if I CAST the field in VARCHAR within WHERE clause then I can use the UPPER function.

so the statement would look like this:

SELECT ID, NAME
FROM TABLE1
WHERE UPPER(CAST(TABLE1.TEXTFIELD1)) LIKE UPPER('%MySearchText%')

Thanks once again
0
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11829099
Yep, that's fine, but I would check the performance of the SQL with and without the UPPER.  Using a function in the where means that usage of indexes is adversely affected.

Tony
0
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.

 

Author Comment

by:juliusrai
ID: 11829123
Please do it as I m not expert in SQL so I was also thinking about that.

Pleas let me know if you have better than this.

Also please give me the code using the COLLATE function if you can.

Thanks
0
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11829460
Doh....I may have mislead you slightly.  I went back to look at the code that I wrote to do this and it appears that the case sensitivity is handled on a Left Outer Join, as you can see below.

I am not sure you can do this on a WHERE clause.

SELECT Table1.*,Table2.* FROM Table1 LEFT OUTER JOIN Table2 ON Table1.Code = Table1.Code_Ref COLLATE SQL_Latin1_General_CP1_CI_AS


Sorry
Tony
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11866639
Closed, 125 points refunded.
Netminder
Site Admin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

756 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