 	</cfquery>
 
 	<!---- column names in order ---->
-	<cfquery name="CTTAXON_TERM" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
+	<cfquery name="dCTTAXON_TERM" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
 		select
 			*
 		from

		<cfquery name="ud" datasource="uam_god">
			update htax_export set status='export_done' where export_id='#q.export_id#'
		</cfquery>
			update htax_export set status='export_done' where export_id='#q.export_id#'
			<cfabort>
	</cfif>

	<cfquery name="dataset" datasource="uam_god">

	<cfset tterms=listDeleteAt(tterms,listFind(tterms,'SOURCE'))>
	<cfset tterms=listDeleteAt(tterms,listFind(tterms,'TAXON_NAME_ID'))>
	<cfset tterms=listDeleteAt(tterms,listFind(tterms,'SCIENTIFIC_NAME'))>
	<cfset tterms=listDeleteAt(tterms,listFind(tterms,'EXPORT_ID'))>


	<!--- AND GET RID OF NONCLASSIFICATION TERMS ---->

	<CFQUERY NAME="nct" dbtype="query">
		select taxon_term from dCTTAXON_TERM where IS_CLASSIFICATION=0
	</CFQUERY>
	<cfloop query="nct">
		<cfif listcontainsnocase(tterms,taxon_term)>
			<cfset tterms=listDeleteAt(tterms,listFindnocase(tterms,taxon_term))>
		</cfif>
	</cfloop>




	<cfloop query="d">

	<cftransaction>
		<!--- reset variables ---->
		<cfloop list="#tterms#" index="i">
			<cfset "variables.#i#"="">
		</cfloop>
<cftry>
		<cfset variables.TID=d.TID>
		<cfset variables.PARENT_TID=d.PARENT_TID>
		<cfset "variables.#RANK#"=d.term>



		<!---- loop a bunch...---->
		<cfloop from="1" to="500" index="l">
			<cfif len(variables.PARENT_TID) gt 0>
				<cfquery name="next" datasource="uam_god" cachedwithin="#createtimespan(0,0,60,0)#">
					select * from hierarchical_taxonomy where tid=#variables.PARENT_TID#
				</cfquery>
				<cfset variables.TID=next.TID>
				<cfset variables.PARENT_TID=next.PARENT_TID>
				<cfset "variables.#next.RANK#"=next.term>
			<cfelse>
				<cfbreak>
			</cfif>
		</cfloop>
		<cfquery name="thisNoClass" datasource="uam_god">
			select TERM_TYPE,TERM_VALUE from htax_noclassterm where tid=#d.tid#
		</cfquery>

		<cfset dNoClassTerm=queryNew("TERM_TYPE,TERM_VALUE")>
		<!---- need to merge ---->
		<cfloop query="nct">
			<cfquery name="tnctv" dbtype="query">
				select distinct(TERM_VALUE) from thisNoClass where term_type='#taxon_term#'
			</cfquery>
			<cfset thisMergedVal=valuelist(tnctv.TERM_VALUE,";")>
			<cfset queryaddrow(dNoClassTerm,
				{TERM_TYPE="#nct.taxon_term#",
				TERM_VALUE="#thisMergedVal#"}
			)>
		</cfloop>


	<cfquery name="ins" datasource="uam_god">
		insert into cf_temp_classification_fh (
			<cfloop list="#tterms#" index="i">
				#i#,
			</cfloop>
			<cfloop query="dNoClassTerm">
				#TERM_TYPE#,
			</cfloop>
			STATUS,
			username,
			SOURCE,
			SCIENTIFIC_NAME,
			export_id
		) values (
			<cfloop list="#tterms#" index="i">
				'#evaluate("variables." & i)#',
			</cfloop>
			<cfloop query="dNoClassTerm">
				'#TERM_VALUE#',
			</cfloop>
			'autoinsert_from_hierarchy',
			'#q.username#',
			'#dataset.source#',
			'#d.term#',
			'#q.export_id#'
		)
		</cfquery>
	<cfquery name="goit" datasource="uam_god">
		update hierarchical_taxonomy set status='pushed_to_bl' where tid=#d.tid#
	</cfquery>


		<cfcatch>

				<cfquery name="blargh" datasource="uam_god">
					insert into htax_export_errors (
						export_id,
						term,
						term_type,
						message,
						detail,
						sql
					) values (
						'#q.export_id#',
						'#term#',
						'#rank#',
						'#cfcatch.message#',
						'#cfcatch.detail#',
						<cfif isdefined("cfcatch.sql")>
							'#cfcatch.sql#'
						<cfelse>
							'NOT AVAILABLE'
						</cfif>
					)
				</cfquery>
				<cfquery name="goit" datasource="uam_god">
					update hierarchical_taxonomy set status='pushed_to_bl_FAIL' where tid=#d.tid#
				</cfquery>




		</cfcatch>
		</cftry>



		</cftransaction>
	</cfloop>
</cfoutput>
