SQL Update Dynamic Columns
Hi,
Is there an easy way to write an sql UPDATE statement where the columns to be updated are not known in advance? I am thinking of the equivalent of 0=0 in GET statement. For example:
SELECT *
FROM myTable
WHERE 0=0
<cfif structKeyExists( arguments, 'columnA' )>
and columnA = <cfqueryparam value="#arguments.columnA#">
</cfif>
The 0=0 does not work in UPDATE statement. I can use any column whose values I know will never change such as the primary key. However, it only works if the primary key is not auto-increment. Unfortunately, many of my tables use auto-increment primary key.
UPDATE myTable
SET primaryKey = primaryKey
<cfif structKeyExists( arguments, 'columnA' )>
, columnA = <cfqueryparam value="#arguments.columnA#">
</cfif>
Is there a good alternative? Thank you.
Regards,
