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 > Data Access, Manipulation & Batch Languages > ANSI SQL > WildCard in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-03, 09:05
geraldjr30 geraldjr30 is offline
Registered User
 
Join Date: Nov 2003
Posts: 9
WildCard in SQL

Hi,

I am developing a coldfusion page. I have the following query in my page:

<cfquery name = "NewApprovalQuery2" datasource = "first_products">
SELECT * from tbl_Travel
WHERE
(OrderNo is null)
AND (approved = 'no'
OR in_VFC = 'no')
AND tbl_travel.traveler like
(SELECT tbl_names.[LastName] FROM tbl_names
WHERE LastName = '#GetAuthUser()#')

ORDER BY

<cfswitch expression="#sort#">
<cfcase value="1">traveler, program</cfcase>
<cfcase value="2">traveler desc, program</cfcase>
<cfcase value="3">program</cfcase>
<cfcase value="4">program desc</cfcase>
<cfcase value="5">start_date, traveler, program</cfcase>
<cfcase value="6">start_date desc, traveler, program</cfcase>
<cfcase value="7">city, traveler, program</cfcase>
<cfcase value="8">city desc, traveler, program</cfcase>
</cfswitch>
</cfquery>

I would like to know how to put wildcard % characters around the nested query. I tried the following, but to no avail:

<cfquery name = "NewApprovalQuery2" datasource = "first_products">
SELECT * from tbl_Travel
WHERE
(OrderNo is null)
AND (approved = 'no'
OR in_VFC = 'no')
AND tbl_travel.traveler like
%(SELECT tbl_names.[LastName] FROM tbl_names
WHERE LastName = '#GetAuthUser()#')%

ORDER BY

<cfswitch expression="#sort#">
<cfcase value="1">traveler, program</cfcase>
<cfcase value="2">traveler desc, program</cfcase>
<cfcase value="3">program</cfcase>
<cfcase value="4">program desc</cfcase>
<cfcase value="5">start_date, traveler, program</cfcase>
<cfcase value="6">start_date desc, traveler, program</cfcase>
<cfcase value="7">city, traveler, program</cfcase>
<cfcase value="8">city desc, traveler, program</cfcase>
</cfswitch>
</cfquery>


Can someone help me with the syntax?


Thanks in advance,
geebee
Reply With Quote
  #2 (permalink)  
Old 11-18-03, 12:17
satish_ct satish_ct is offline
Registered User
 
Join Date: Nov 2003
Location: Bangalore, INDIA
Posts: 333
Thumbs up Re: WildCard in SQL

Hi,

Use IN instead of like in Ur Query.

SELECT * from tbl_Travel
WHERE
(OrderNo is null)
AND (approved = 'no'
OR in_VFC = 'no')
AND tbl_travel.traveler IN
(SELECT tbl_names.[LastName] FROM tbl_names
WHERE LastName = '#GetAuthUser()#')

ORDER BY
<cfswitch expression="#sort#">
<cfcase value="1">traveler, program</cfcase>
<cfcase value="2">traveler desc, program</cfcase>
<cfcase value="3">program</cfcase>
<cfcase value="4">program desc</cfcase>
<cfcase value="5">start_date, traveler, program</cfcase>
<cfcase value="6">start_date desc, traveler,
program</cfcase>
<cfcase value="7">city, traveler, program</cfcase>
<cfcase value="8">city desc, traveler, program</cfcase>
</cfswitch>
</cfquery>


U can't use the Wild character '%' as u mentioned in Ur Query.

The syntax is LIKE('%');
__________________
SATHISH .
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