How to select Topic Subjects on the first letter? - نوشته شده در (631 Views)
Junior Member
ILLHILL
مطلب: 341
341
Don't know if this is the place, but it might come in handy in some mods.
I was wondering how I can select topics starting with a certain letter. Say, all topics starting with the letter A, how would I go about this?
strSql = strSql & " ORDER BY T.T_SUBJECT ASC"

That's the part to order them in an alphabetic way, but I need
some addition like "if bla bla = "a" then"

Anybody got any experience in this?
Greets & thanks,

Dominic
<
 پیش‌فرض مرتب‌سازی برای تاریخ DESC به معنی جدیدترین است  
 تعداد در صفحه 
نوشته شده در
Junior Member
JBaldwin
مطلب: 137
137
One way to do it is with the LIKE operator. Depending on which type DB your are using an example would look like this:

Code:
strSql = strSql & "WHERE T.T_SUBJECT LIKE 'A%' ORDER BY T.T_SUBJECT ASC"

Sometimes with an MS Access DB you would need to use an asterisk (*)as the wild card operator instead of the percent sign (%):

Code:
strSql = strSql & "WHERE T.T_SUBJECT LIKE 'A*' ORDER BY T.T_SUBJECT ASC"

Where 'A%' or 'A*' is the First letter of the subject you want to search for.

Of course this is just one way to do it. I am sure there is a better, more efficient way to go about it. Have a look in members.asp, there is a SQL statement there that uses an initial as a search. I am sure one could rip the snippet out of there and modify it for your needs.<
نوشته شده در
Junior Member
ILLHILL
مطلب: 341
341
Great! Thanks! I will look into this. Thanks again!
Greets, Dominic
<
نوشته شده در
Forum Moderator
AnonJr
مطلب: 5768
5768
Just FYI: I use the LIKE operator in a lot of my Access apps at work and the percent sign (%) has worked just fine in all of the ASP-based programs - I haven't used it in any of my desktop apps yet since I'm trying to move almost all our department apps to a web-based system.<
نوشته شده در
Average Member
Zuel
مطلب: 540
540
I did this too, except I created an array with all my values. Sample below.
Code:

Dim LetterArray : LetterArray = Array("[0-9]", "A", "B", "C", "D", "E", "F", "G", "H", "I", 
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")

For i = 0 to UBound(LetterArray)
strSql = strSql & "WHERE T.T_SUBJECT LIKE '" & LetterArray(i) & "%' ORDER BY T.T_SUBJECT ASC"
Next

Shows you the posibilities.<
My Completed Mods: News Mod | Zuel's Avatar Add-on
In Development: World of Warcraft Member Roster | [C# Based Forum]
Note - I may take a few days to recieve your email. Hotmail filters all new emails as junk. Would be best to post all questions, concerns in a forum topic to catch my immediate attention. This way others can assist and also correct any similar mistakes.
MSN / E-Mail: ucyimDa_Ruler@Hotmail.com

Personal Bookmarks: How to work a DBS File
نوشته شده در
Junior Member
ILLHILL
مطلب: 341
341
Thanks guys! Appreciate it!
Greets & thanks,

Dominic
<
 
شما باید یک متن وارد کنید