If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Using Like or Wildcard

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-06-03, 14:44
Wanda Wanda is offline
Registered User
 
Join Date: Nov 2002
Posts: 3
Using Like or Wildcard

I am searching against a sql database and I want to return all active courses and all courses whose field code begins with a 10. This is the table (LEDef) & some of the info that is in the field.

LEDef_Cd
DB356
40ILTC0007
HW442
51NWAC000020
10-CSSR-2013
10-FESW-0002

I want to return only the "10-" stuff. Here is part of the code I'm using in 2 of my files. I've tried everything but nothing seems to work:

r.open "SELECT LEDef_PK FROM LEDef WHERE LEDef_ActiveInd = 1 AND LEDef_Cd LIKE '10-%'"

r.Open "SELECT LEDef_Cd, LEDef_Name, LEDef_Desc, LEDef_ActiveInd, FROM LEDef WHERE LEDef_ActiveInd = 1 and LEDef_Cd LIKE '10-%'"and LEDef_PK = " & Request.QueryString("id"),
Reply With Quote
  #2 (permalink)  
Old 06-09-03, 07:08
mojza mojza is offline
Registered User
 
Join Date: Aug 2002
Location: Prague
Posts: 77
Re: Using Like or Wildcard

have you tried enclosing - charactrer in brackets? e.g. LIKE '10[-]%'
Reply With Quote
  #3 (permalink)  
Old 06-09-03, 09:28
Donner Donner is offline
Registered User
 
Join Date: May 2003
Posts: 26
A question regarding exactly what you are looking for, because what you described in your question seems different than whats in your query.

Quote:
[i]I want to return all active courses and all courses whose field code begins with a 10
This is saying the record must have LEDef_ActiveInd = 1 or LEDef_Cd LIKE '10-%', either one of these will satisfy the conditions for your result set.

What you have coded says a record must have both LEDef_ActiveInd = 1 and LEDef_Cd LIKE '10-%' to be included. Having one or the other is not enough.

If you want either condition to be enough try

SELECT LEDef_PK FROM LEDef WHERE LEDef_ActiveInd = 1 OR LEDef_Cd LIKE '10-%'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On