I have a table that I need to update where all columns are optionally passed to the method.
Then I use ColdFusion to check if each column has passed and add it to the update request.
What is the best way to do this? I cannot always update the user_id field because it is an identification field. Is there something similar to setting 1 = 1, like mine below, that will work? The only problem is that commas cause syntax errors.
Thanks for any help.
update users
set 1 = 1
<cfif len(arguments.userType)>,user_type =
<cfif len(arguments.primaryGroupId)>,primary_group_id =
<cfif len(arguments.email)>,email = '#arguments.email#'</cfif>
<cfif len(arguments.password)>,password = '#arguments.password#'</cfif>
<cfif len(arguments.firstName)>,first_name = '#arguments.firstName#'</cfif>
<cfif len(arguments.lastName)>,last_name = '#arguments.lastName#'</cfif>
<cfif len(arguments.status)>,status = '#arguments.status#'</cfif>
<cfif len(arguments.languageId)>,language_id =
<cfif len(arguments.gmtOffset)>,gmt_offset = '#arguments.gmtOffset#'</cfif>
where user_id =
source
share