Skip to main content
May 22, 2007
Answered

Wierd SQL happening

  • May 22, 2007
  • 1 reply
  • 196 views
I'm using the following SQL statement

<cfquery name="rscustomer" datasource="rayannesql">
SELECT firstname, lastname, address
FROM dbo.customer
WHERE lastname = '%#FORM.lastname#%'
Order By firstname
</cfquery>

when I type in a last name value, I know exists in the database into a search box, I get a blank page back.

I don't understand why. I tried removing the WHERE clause and get all results back from the database
    This topic has been closed for replies.
    Correct answer GMina
    if you are going to do a wildcard search using the % symbol you will need to use the LIKE operator instead of the = operator. Your SQL statement should look like:

    SELECT firstname, lastname, address
    FROM dbo.customer
    WHERE lastname LIKE ('%#FORM.lastname#%')
    ORDER BY firstname

    1 reply

    GMinaCorrect answer
    Participant
    May 22, 2007
    if you are going to do a wildcard search using the % symbol you will need to use the LIKE operator instead of the = operator. Your SQL statement should look like:

    SELECT firstname, lastname, address
    FROM dbo.customer
    WHERE lastname LIKE ('%#FORM.lastname#%')
    ORDER BY firstname