|
|
Question : Cold fusion & SQL CFIF "if variable not present, alt query" problem
|
|
|
|
This has always been a problem, and I now realize that the way I tried to fix it never worked.
sometimes the page that calls this query does not have a "article_id" to pass to this. Sometimes it is undefined.
I have an sql statement that is supposed to execute : (AND article_id = #article_id#)
or
one that is supposed to be run if not :
(AND article_id = (SELECT max(article_id) FROM articles2 x WHERE article_type = 'M' AND x.ministry_id = ministries.ministry_id AND article_date = (SELECT max(article_date) FROM articles2 y WHERE article_type = 'M' AND Y.ministry_id = ministries.ministry_id))
the first one (AND article_id = #article_id#) is executed if the article_id variable is present, otherwise the other, longer one does.
I have
<cfif IsDefined("article_id") and neq "not_present">
as a CFIF condition(s) but this does not work.
I tried setting the variable to "not_present" (it would be overwritten if it were) but this still does not work. I need something that accounts for it either being completely absent OR being defined as being blank
full SQL query below
This has been hit against the DB (with alternate conditions used [the cflogic taken out]) and it works fine.
all other variables will always be present, just not always an article_id
SELECT article_date as update_date, article_title as update_title, created_by as ministry_leader, ministry_desc, article_id, mission_statement, author_name, (SELECT rtrim(first_name) + ' ' + rtrim(last_name) from users where user_id = created_by) as u_by, file_content1, file_content2, file_content3 FROM articles2, ministries WHERE articles2.ministrY_id = ministries.ministry_id AND ministries.ministry_id = #ministry_id# AND articles2.article_type = 'M' <cfif IsDefined("article_id") and neq "not_present"> AND article_id = #article_id# <cfelse> AND article_id = (SELECT max(article_id) FROM articles2 x WHERE article_type = 'M' AND x.ministry_id = ministries.ministry_id AND article_date = (SELECT max(article_date) FROM articles2 y WHERE article_type = 'M' AND Y.ministry_id = ministries.ministry_id))
|
|
|
|
Answer : Cold fusion & SQL CFIF "if variable not present, alt query" problem
|
|
>> <cfif IsDefined("article_id") and neq "not_present">
The second condition isn't defined properly, it should be more like
<cfif IsDefined("article_id") and article_id neq "not_present">
>> I need something that accounts for it either being completely absent OR >> being defined as being blank
What do you mean by "blank"? Do you mean the value of "article_id" is literally the string "not_present"
ie <cfset article_id = "not_present">
... or that it's value is an empty string
ie <cfset article_id = "">
|
|
|
|