The code below copies information from one table to another (I am changing my database structure).
The code works, however as you can imagine it updates all entries in the zipcode table for matching "Denver" and "CO" records and I only want to update the first Denver it comes to.
Is there some SQL statement I can add to only update the first matching record it finds?
The code works, however as you can imagine it updates all entries in the zipcode table for matching "Denver" and "CO" records and I only want to update the first Denver it comes to.
Is there some SQL statement I can add to only update the first matching record it finds?
Code:
<!--- Copy coord, county and set topMetro to 1 in zipcode tabel from CS table --->
<cfquery datasource="#Application.DSN#" name="GetAllCs">
SELECT csName, county, coords, stateFk
FROM cs
WHERE csid > 52
</cfquery>
<cfif GetAllCs.RecordCount GTE 1 >
<CFLOOP QUERY="GetAllCs">
<cfset cityCapsWithoutDashes = REReplace(GetAllCs.csName,'-',' ','All')>
<cfquery name="GetStates" datasource="#Application.DSN#">
SELECT stateAbv
FROM state
WHERE stateId = #GetAllCs.stateFk#
</cfquery>
<!--- update the listing table with the info from the table above --->
<CFQUERY DATASOURCE="#Application.DSN#" >
UPDATE zipcodes
SET topMetro=<cfqueryparam value='1' cfsqltype='CF_SQL_INTEGER'>,
county=<cfqueryparam value='#trim(GetAllCs.county)#' cfsqltype='cf_sql_varchar'>,
coords=<cfqueryparam value='#trim(GetAllCs.coords)#' cfsqltype='cf_sql_varchar'>
WHERE zipcodes.city = <cfqueryparam value='#cityCapsWithoutDashes#' cfsqltype='cf_sql_varchar'>
AND zipcodes.stateAbv = '#GetStates.stateAbv#'
</cfquery>
<cfoutput>#cityCapsWithoutDashes#, #GetStates.stateAbv# #GetAllCs.county# #GetAllCs.coords#<br></cfoutput>
</CFLOOP>
</cfif>
<h1>Completed <cfoutput>#GetAllCs.recordcount#</cfoutput></h1>