Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to compare alphabets?

Author  Topic 

SQLGuruji
Starting Member

6 Posts

Posted - 2010-01-20 : 09:04:06
Hi,

I need to run a query to select records from a table where values in a column are like "A,B,C,D,E,...."

like"
select * from table where alphabets >= A and alphabets <= D.

The column data type of alphabets is "text"

Thanks!

shan
Yak Posting Veteran

84 Posts

Posted - 2010-01-20 : 09:19:01
Try this...
select * from table where ASCII(Convert(varchar(1),alphabets)) >= 65 and ASCII(Convert(varchar(1),alphabets)) <= 68


-Shan
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-20 : 09:25:45
What is your SQL Server version?

Important:
ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

text
Variable-length non-Unicode data in the code page of the server and with a maximum length of 2^31-1 (2,147,483,647) characters

Are you sure you want to search a text field with maximum of 2,147,483,647 possible characters for a value like A?????


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SQLGuruji
Starting Member

6 Posts

Posted - 2010-01-20 : 12:30:16
Shan thanks your query worked great! and webfred thanks for your reply.
Go to Top of Page

shan
Yak Posting Veteran

84 Posts

Posted - 2010-01-21 : 08:56:53
You are welcome


-Shan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-25 : 02:00:06
or

select * from table where alphabets like '[A-D]%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -