I am trying to run a query to cross-check the values a user entered against the database. I want to do this so that before the user adds a record, the record must not already exist. This is for a list of street names.
There are four items the user might select (3 are required). These are PREFIX, NAME, TYPE, and SUFFIX. For example, for the street named "Park Ave NE", "Park" is the NAME, "Ave" is the TYPE, and "NE" is the SUFFIX (there is no PREFIX entered in this example).
If I run the following query:
<CFQUERY NAME="qCheckSt">
SELECT NAME, PREFIX, SUFFIX, TYPE
FROM NAMES
WHERE NAME = '#Form.Name#'
AND PREFIX = '#Form.Prefix#'
AND TYPE = '#Form.Type#'
AND SUFFIX = '#Form.Suffix#'
</CFQUERY>
I will get a "returned 0 records" even if this exists. The problem is with the PREFIX. If I run the above query but take out the statement "AND PREFIX = '#Form.Prefix#'", I get a "returned 1 record".
It's when a value is null that I am having the problem. I tried doing it both ways. Meaning, that if the user doesn't select a PREFIX, the value NULL will be checked. This didn't work, so I took out the value NULL and it still didn't work.
Is there something simple that I am not doing correctly?
There are four items the user might select (3 are required). These are PREFIX, NAME, TYPE, and SUFFIX. For example, for the street named "Park Ave NE", "Park" is the NAME, "Ave" is the TYPE, and "NE" is the SUFFIX (there is no PREFIX entered in this example).
If I run the following query:
<CFQUERY NAME="qCheckSt">
SELECT NAME, PREFIX, SUFFIX, TYPE
FROM NAMES
WHERE NAME = '#Form.Name#'
AND PREFIX = '#Form.Prefix#'
AND TYPE = '#Form.Type#'
AND SUFFIX = '#Form.Suffix#'
</CFQUERY>
I will get a "returned 0 records" even if this exists. The problem is with the PREFIX. If I run the above query but take out the statement "AND PREFIX = '#Form.Prefix#'", I get a "returned 1 record".
It's when a value is null that I am having the problem. I tried doing it both ways. Meaning, that if the user doesn't select a PREFIX, the value NULL will be checked. This didn't work, so I took out the value NULL and it still didn't work.
Is there something simple that I am not doing correctly?