Example 3: Complex queries

201–225 of 6,860
IDNameCodeDescriptionLatitudeLongitude
4,764 Glory Cove BAY bay/inlet 46° 58′ 11″ S 168° 09′ 35″ E
4,765 Sailors Rest BAY bay/inlet 46° 58′ 11″ S 168° 08′ 23″ E
4,772 Goose Cove BAY bay/inlet 46° 58′ 11″ S 168° 09′ 00″ E
4,805 Ocean Beach BCH beach 46° 58′ 11″ S 168° 10′ 11″ E
1,607 The Gutter ISTH isthmus 46° 57′ 36″ S 167° 41′ 23″ E
1,609 Cavalier Creek STRM stream 46° 57′ 36″ S 167° 43′ 11″ E
1,617 South West Arm BAY bay/inlet 46° 57′ 36″ S 167° 55′ 48″ E
2,588 Steep Head PNT point 46° 57′ 36″ S 168° 10′ 48″ E
4,787 Boat Passage Islands ISLD island 46° 57′ 36″ S 168° 09′ 00″ E
4,788 Bravo Island ISLD island 46° 57′ 36″ S 168° 07′ 47″ E
4,806 Paua Beach BCH beach 46° 57′ 36″ S 168° 04′ 48″ E
1,606 Mason Bay BAY bay/inlet 46° 57′ 00″ S 167° 41′ 59″ E
1,611 Wreck Creek STRM stream 46° 57′ 00″ S 167° 45′ 00″ E
1,613 Walkers Hill HILL hill 46° 57′ 00″ S 167° 47′ 23″ E
1,618 Ogles Creek STRM stream 46° 57′ 00″ S 167° 58′ 11″ E
2,446 Euchre Creek STRM stream 46° 57′ 00″ S 168° 02′ 23″ E
2,447 Hapuatuna Bay BAY bay/inlet 46° 57′ 00″ S 168° 04′ 11″ E
2,448 Gentian Cove BAY bay/inlet 46° 57′ 00″ S 168° 07′ 12″ E
2,559 Burnt Point PNT point 46° 57′ 00″ S 168° 06′ 36″ E
2,560 Refuge Island ISLD island 46° 57′ 00″ S 168° 07′ 12″ E
2,561 Bull Point PNT point 46° 57′ 00″ S 168° 04′ 48″ E
2,562 Tommy Island ISLD island 46° 57′ 00″ S 168° 07′ 12″ E
2,563 Groper Island ISLD island 46° 57′ 00″ S 168° 08′ 23″ E
2,564 Crayfish Island ISLD island 46° 57′ 00″ S 168° 07′ 47″ E
2,582 Goat Island ISLD island 46° 57′ 00″ S 168° 08′ 23″ E
201–225 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:-