Ask a Question related to Coldfusion Database Access, Design and Development.
-
Unamailer #1
IF statement within CFQUERY/SQL
Does anyone know if SQL has an IF statement? I can't seem to find an example
that works.
I know it is possible to perform a CFIF within a CFQUERY. However, I can't
compare one of the DB fields to a variable or constant while within that
CFQUERY.
Here is some pseudo-code of what I am trying to do.
SELECT type, category, description, datein
FROM someTable
WHERE type = 'K'
IF (category = 5) THEN
AND dateIn = 042105
END IF
None of the values in the WHERE statement are CF variables. Basically, I only
want to check the dateIn value if the category field from the table equals 5.
Is this possible?
Thanks in advance for the help!!
Unamailer Guest
-
Output from different datasource in cfquery statement
i've make 2 cfquery statements. one refers to datasource DatStudent and another one refers to datasource DatModul. in coldfusion admin, DatStudent... -
Error executing a cfquery update statement. PLEASE HELP
I have been over and over this. I am trying to update a simple table. I took this script from the same server using a different DSN. I keep... -
cfquery insert into sql statement
Hello, I have a simple SQL statement (within a cfquery tag) that will not insert: <cfquery datasource="shoptrak" name="insert"> INSERT INTO... -
need help with cfquery
This should be an easy one ... unfortunately I am a n00b to sql and CF. I am trying to display a certain column in a table, the most recent one. I... -
CFQUERY with IF THEN ELSE
I have a CFQUERY which works perfectly and now I would like to add a little date calculation to this query to filter it little more. The query is a... -
mattis_72 #2
Re: IF statement within CFQUERY/SQL
I dont really know what you mean, but this may work?
SELECT type, category, description, datein
FROM someTable
WHERE type = 'K'
<CFIF (category eq 5) >
AND dateIn = 042105
</CFIF>
mattis_72 Guest
-
The ScareCrow #3
Re: IF statement within CFQUERY/SQL
As far as I know you can't do this in pure sql. But you could do it in a
stored procedure if your db allows them.
But I think the following should return what you want.
<cfquery>
SELECT type, category, description, datein
FROM someTable
WHERE type = 'K'
AND category <> = 5
UNION
SELECT type, category, description, datein
FROM someTable
WHERE type = 'K'
AND category = 5
AND dateIn = 042105
</cfquery>
Ken
The ScareCrow Guest
-
Jochem van Dieten - TMM #4
Re: IF statement within CFQUERY/SQL
Unamailer wrote:
CASE WHEN x THEN y ELSE z END> Does anyone know if SQL has an IF statement?
SELECT type, category, description, datein> I know it is possible to perform a CFIF within a CFQUERY. However, I can't
> compare one of the DB fields to a variable or constant while within that
> CFQUERY.
>
> Here is some pseudo-code of what I am trying to do.
>
> SELECT type, category, description, datein
> FROM someTable
> WHERE type = 'K'
> IF (category = 5) THEN
> AND dateIn = 042105
> END IF
FROM someTable
WHERE type = 'K' AND
CASE WHEN category = 5 AND dateIn = 042105 THEN TRUE
WHEN category = 5 THEN FALSE ELSE TRUE END
Ugly, but should work.
Jochem
--
Jochem van Dieten
Team Macromedia Volunteer for ColdFusion, beer and fun.
Jochem van Dieten - TMM Guest



Reply With Quote

