Skip to content

Instantly share code, notes, and snippets.

@richardhughes260
Last active December 17, 2015 01:19
Show Gist options
  • Save richardhughes260/5527915 to your computer and use it in GitHub Desktop.
Save richardhughes260/5527915 to your computer and use it in GitHub Desktop.
Select only records with valid e-mail addresses from a table
<!--- Create a new three-column query, specifying the column data types --->
<cfset myQuery = QueryNew("Name, Email, Time, Advanced", "VarChar, VarChar, Time, Bit")>
<!--- Make two rows in the query --->
<cfset newRow = QueryAddRow(MyQuery, 2)>
<!--- Set the values of the cells in the query --->
<cfset temp = QuerySetCell(myQuery, "Name", "Rich", 1)>
<cfset temp = QuerySetCell(myQuery, "Email", "rich@rich.com", 1)>
<cfset temp = QuerySetCell(myQuery, "Time", "9:15 AM", 1)>
<cfset temp = QuerySetCell(myQuery, "Advanced", False, 1)>
<cfset temp = QuerySetCell(myQuery, "Name", "Bob", 2)>
<cfset temp = QuerySetCell(myQuery, "Email", "bob.rich.com", 2)>
<cfset temp = QuerySetCell(myQuery, "Time", "12:15 PM", 2)>
<cfset temp = QuerySetCell(myQuery, "Advanced", True, 2)>
<!--- show the original record set --->
<h3>Original record set</h3>
<cfdump var="#myQuery#" label="Original record set">
<!--- add isValidEmail column --->
<cfset temp = QueryAddColumn(myQuery, "isValidEmail", "VarChar", arrayNew( 1 ))>
<h3>Record Set with isValidEmail added</h3>
<cfdump var="#myQuery#" label="Record Set with isValidEmail added">
<!--- loop over query and set value of isValidEmail --->
<h3>Loop over query and set value of isValidEmail</h3>
<cfloop query = "myQuery">
<cfset temp = QuerySetCell(myQuery, "isValidEmail", isValid('email', email), currentrow)>
<cfoutput>#name# #currentrow# #email# #isValidEmail#</cfoutput><br>
</cfloop>
<h3>Show the record set with isValidEmail set</h3>
<cfdump var="#myQuery#">
<!--- QOQ to select only valid e-mails --->
<cfquery name="myQuery" dbtype="query">
select *
from myQuery
where isValidEmail = 'YES'
</cfquery>
<h3>Show the new record set with onl valid e-mail addresses</h3>
<cfdump var="#myQuery#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment