Solved

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

Posted on 2004-08-17
7
989 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

739 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