Ask a Question related to Coldfusion Database Access, Design and Development.
-
rowbeast #1
dealing with no records returned
Hey All,
I'm setting up a column in DB that gets populated by a number incremented by
1, based on the last column value entered.
My problem happend when there are no prior records in the table that match my
select criteria from the query that determines the number to increment. I
thought using an if statement with the recordset keywork would work, but its
throwing an error that seems to make no sense. Please take a look at the code
below if you dont mind and see if there is something blatently wrong.... (it
may be my logic behind getting the last number too...)
The error i get is: the value "" cannot be converted to a number
and it references this line: <cfset new_sort_id = #getMaxsort.maxsortID# + 1>
Here is my code:
<cfquery datasource="####" name="getMaxsort">
SELECT MAX(sort_id) as maxsortID FROM pages WHERE iid = #form.iid#
</cfquery>
<cfif getMaxsort.recordcount NEQ 0>
<cfset new_sort_id = #getMaxsort.maxsortID# + 1>
<cfelse>
<cfset new_sort_id = 1>
</cfif>
rowbeast Guest
-
dealing with dates
Hello list, I am having a problem coming up with a solution to compare and find the difference between two dates. One of the dates is a GMT... -
limiting the number of records returned
Hi all, The problem I am having is that I built an online query system. The problem is if the search critera is to open or loose, the coldfusion... -
Display Returned Records
What I have is a query that returns all the parts in a service tech's kit. I am then returing the records in a table to show all the components in... -
DIR MX: Dealing with scrollbars
Hi, I have a text member which content changes each time the user clicks on a button. A scrollbar is attached to this text member. I use this... -
checking how many records are returned?
Is there a way to check how many records are returned from a query to the database? -
mxstu #2
Re: dealing with no records returned
If there are no records in the table, SELECT MAX(sort_id) will return NULL.
This "null" is converted to an empty string in CF. Since an empty string is
not a number, CF complains when you try to add "+1"
<cfset new_sort_id = #getMaxsort.maxsortID# + 1>
Use the val() function. It will convert the empty string to zero. However,
using an auto incrementing id column would probably be easier than doing this
all manually.
<cfset new_sort_id = val(getMaxsort.maxsortID) + 1>
mxstu Guest
-
rowbeast #3
Re: dealing with no records returned
thanks Stu, that makes total sense!
I am not using an autoincrementing field as I will be modifing the values at a
later time with a different query for sorting records, but thanks for the
suggestion!
rowbeast Guest



Reply With Quote

