|
-
May 23rd, 2008, 02:11 AM
#1
Thread Starter
Addicted Member
Querying But Considering the Cases
Hi guys,
I was hoping you could help me. I have a problem regarding querying records but I need to consider the cases of the characters.
For example, the 'text_msg' field has 'Hello' and 'hello' on it.
I want to query something like this:
select * from <table> where text_msg = 'Hello'
(which returns records with 'Hello' and exclude 'hello' records
and
select * from <table> where text_msg = 'hello'
(which returns records with 'hello and exclude 'Hello' records.
Thanks in advance
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
May 23rd, 2008, 03:20 AM
#2
Re: Querying But Considering the Cases
Using T-SQL (based on SQL Server) i would use a combination of the LEFT function and the ASCII funtion to get the ASCII value of the first character.
Then you can evalute what to do. See example below
Code:
DECLARE @Test1 AS VARCHAR(10)
SET @Test1 = 'Hello'
SELECT ASCII(LEFT(@Test1,1))
IF ASCII(LEFT(@Test1,1)) BETWEEN 65 AND 90
BEGIN
SELECT 'Uppercase'
-- You would place SELECT code in here for UPPERCASE search
END
IF ASCII(LEFT(@Test1,1)) BETWEEN 97 AND 122
BEGIN
SELECT 'Lowercase'
-- You would place SELECT code in here for LOWER search
END
-- Examples wherer you would use it in the WHERE clause
-------------------------------------------------------
-- Where the first Character it NOT Lower Case
SELECT @Test1
WHERE NOT(ASCII(LEFT(@Test1,1)) BETWEEN 97 AND 122)
-- Where the first Character it NOT Upper Case
SELECT @Test1
WHERE NOT(ASCII(LEFT(@Test1,1)) BETWEEN 65 AND 90)
/*
ASCII Ranges
65 - 90 Upper Case
97 - 122 Lower Case
*/
Run all the code to see the results. Notice that if you change
Code:
SET @Test1 = 'Hello'
to
Code:
SET @Test1 = 'hello'
The results of the bottom two SELECT's change
Last edited by kevchadders; May 23rd, 2008 at 03:40 AM.
-
May 23rd, 2008, 03:43 AM
#3
Re: Querying But Considering the Cases
Code:
select * from <table> where LOWERCASE(text_msg) = 'hello'
Not sure what DB language you use.
Replace LOWERCASE() with equivalent function of your DB language, such as LCase() in Access.
-
May 23rd, 2008, 04:49 PM
#4
Re: Querying But Considering the Cases
Use COLLATE.
Code:
WHERE text_msg = 'Hello' COLLATE SQL_Latin1_General_CP1_CS_AS
-
May 26th, 2008, 09:41 PM
#5
Thread Starter
Addicted Member
Re: Querying But Considering the Cases
Let me check on that now. Thanks. Ill go back with results. Thanks
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|