Copy link to clipboard
Copied
Hello So I have a page and when it loads I would like to have it insert into a table if a record is matched. In the body I have this:
<cfquery name="countlookup" Datasource="#application.datasource#" dbtype="ODBC">
SELECT id as idlx
FROM usercount
</cfquery>
<cfset idl = #countlookup.idlx#>
<cfif #idl# eq '449'>
<cfquery name="countlookup450" Datasource="#application.datasource#" dbtype="ODBC">
INSERT INTO usercount (id)
values (450)
</cfquery></cfif>
Issue I'm seeing is the page loads and doesn't insert anything in the usercount table. What am I messing up? I'm using Coldfusion 2021 woth SQL 2019.
Thanks
What you're missing is a where clause in your select query.
The query is very likely returning multiple rows and the first row does not match '449'.
Copy link to clipboard
Copied
What you're missing is a where clause in your select query.
The query is very likely returning multiple rows and the first row does not match '449'.
Copy link to clipboard
Copied
Yes you are correct. It's always the small things you miss. after adding where id = '449' it worked.
Thanks
Copy link to clipboard
Copied
You're welcome. Glad it was an easy fix.