Example 3: Complex queries

176–200 of 6,860
IDNameCodeDescriptionLatitudeLongitude
1,565 Table Hill HILL hill 47° 02′ 23″ S 167° 50′ 24″ E
4,760 Pikaroro Bay BAY bay/inlet 47° 02′ 23″ S 168° 12′ 36″ E
125,852 Lords River/Tutaekawetoweto STRM stream 47° 02′ 23″ S 168° 01′ 12″ E
129,201 Stewart Island/Rakiura ISLD island 47° 02′ 23″ S 168° 03′ 00″ E
1,593 Doughboy Bay BAY bay/inlet 47° 01′ 48″ S 167° 40′ 48″ E
4,771 Heron River STRM stream 47° 01′ 48″ S 168° 06′ 36″ E
4,802 Pikaroro Point PNT point 47° 01′ 48″ S 168° 12′ 36″ E
4,807 Adventure Hill HILL hill 47° 01′ 48″ S 168° 04′ 48″ E
1,566 Doughboy Hill HILL hill 47° 01′ 12″ S 167° 43′ 11″ E
1,615 Waterfall Creek STRM stream 47° 00′ 35″ S 167° 51′ 36″ E
4,761 Chew Tobacco Bay BAY bay/inlet 47° 00′ 35″ S 168° 11′ 59″ E
125,848 East Cape/Koromere PNT point 47° 00′ 35″ S 168° 13′ 11″ E
1,567 Adams Hill HILL hill 47° 00′ 00″ S 167° 42′ 36″ E
4,773 Chew Tobacco Creek STRM stream 47° 00′ 00″ S 168° 10′ 48″ E
4,786 Pihore Island ISLD island 47° 00′ 00″ S 168° 12′ 36″ E
4,762 Lauras Leg BAY bay/inlet 46° 59′ 24″ S 168° 11′ 59″ E
4,804 Chew Tobacco Point PNT point 46° 59′ 24″ S 168° 12′ 36″ E
1,614 Traills Hill HILL hill 46° 58′ 47″ S 167° 48′ 00″ E
1,616 Rakeahua River STRM stream 46° 58′ 47″ S 167° 49′ 48″ E
4,763 Murrays Mistake BCH beach 46° 58′ 47″ S 168° 11′ 23″ E
4,766 Big Glory Bay BAY bay/inlet 46° 58′ 47″ S 168° 05′ 24″ E
125,853 Lords River/Tutaekawetoweto STRM stream 46° 58′ 47″ S 167° 58′ 11″ E
1,608 Kilbride LOC locality 46° 58′ 11″ S 167° 40′ 48″ E
1,610 Leask Creek STRM stream 46° 58′ 11″ S 167° 41′ 59″ E
1,619 Bald Hill HILL hill 46° 58′ 11″ S 167° 57′ 36″ E
176–200 of 6,860

Sometimes a record set will need to combine data from different tables. We can implement this by creating a view in the database (example 2) or by writing the join directly within the table attribute. Here we have also added a clause to restrict the records to those below 45° south.

Features of this example:

  • The tables are joined within the table attribute, so we don't need to set up a database view.
  • A where attribute controls the subset of records to be displayed.
  • As pointdescriptioncode appears in both tables, we must qualify the column with the table name.
  • The expression attribute is used for latitude and longitude to call a user-defined function.
  • Query caching using the cachedwithin attribute.
  • The 'glacier_lavender' skin.
  • Locale-specific formatting for 'English (US)' (change this using the selector at bottom right).
Source code for this example 
<!--- 
Note that the database for this example must be set up as a datasource first. The Microsoft Access database is located in the examples folder. Place the datasource name in the request.dsn variable.

Microsoft Access is not recommended for web purposes, and is provided here for demonstration purposes only. Better performance will be achieved with enterprise databases.
--->

<cfimport prefix="esw" taglib="../customtags/eswsoftware/">

<cfif structKeyExists(url, "relatedId")>
	<cfoutput><p>Record selected: #htmlEditFormat(url.relatedId)#</p></cfoutput>
</cfif>

<esw:sortableplus 
	link="example3.cfm?relatedid=##relatedid##"
	table="namedata inner join pointdes on namedata.pointdescriptioncode = pointdes.pointdescriptioncode"
	dbms="Microsoft Access"
	datasource="#request.dsn#"
	sortBy="Latitude"
	key="relatedid"
	style="width : 600px"
	where="latitude < -45"
	cachedwithin="#createTimeSpan(0, 0, 10, 0)#"
	skin="glacier_lavender"
>

	<esw:column
		column="relatedid"
		caption="ID"
		type="numeric"
		sortDirection="asc"
	/>
	
	<esw:column
		column="pointname"
		caption="Name"
	/>
	
	<esw:column
		column="pointdes.pointdescriptioncode"
		caption="Code"
	/>
	
	<esw:column
		column="pointdescriptionname"
		caption="Description"
	/>
	
	<esw:column
		column="Latitude"
		type="numeric"
		expression="##caller.dmsFormat(latitude, 'NS')##"
	/>
	
	<esw:column
		column="Longitude"
		type="numeric"
		expression="##caller.dmsFormat(Longitude, 'EW')##"
	/>
	
</esw:sortableplus>

<cfscript>
	function dmsFormat(value) {
		var temp = abs(value);
		var d = int(temp);
		var m = 0;
		var s = 0;
		var signIndicator = arrayLen(arguments) gt 1;
		var result = "";
		temp = (temp - d) * 60;
		m = int(temp);
		temp = (temp - m) * 60;
		s = int(temp);
		result = "#d#&##176; #numberFormat(m, "00")#&##8242; #numberFormat(s, "00")#&##8243;";
		
		if ( signIndicator )
			if ( value lt 0 )
				result = result & " " & right(arguments[2],1);
			else 
				result = result & " " & left(arguments[2],1);
		else
			if ( value lt 0 )
				result = "-" & result;
		return result;
	}
</cfscript>

To run the example, you will need to:-