Solved

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

Posted on 2004-08-17
7
983 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 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

10 Experts available now in Live!

Get 1:1 Help Now