Excerpted from CF Advisor, January 1999.

Using Structures to Delete a Session Variable
Joining Multiple Tables: The Correct Syntax
Emulating a "Words" Function

Using Structures to Delete a Session Variable

In addition to making it easy to refer to session and application variables, using structures also provides a simple and straightforward means to delete such a variable. The StructDelete function does the trick.

The specific format of the StructDelete would be to name the variable type (session or application) as the first parameter, without quotes, and to name the specific variable in the second parameter, in quotes. For example, the following deletes the session variable "login":

<CFSET Foo = StructDelete(session,'login')>>

This isn't too obvious from the reference manual, because it doesn't actually explain what should and shouldn't be quoted, and it speaks in terms of structures and their keys. In our example, session is the structure and "login" is the key.


Joining Multiple Tables: The Correct Syntax

If you've tried to join more than one table in SQL, you may have encountered a challenge in figuring out the correct syntax. Here is a three-table join in the two different forms of join syntax: the first uses the JOIN keywords in the FROM clause while the second defines the joins in the WHERE clause.

Either approach will work in either Access or SQL Server.

SELECT * FROM (tablea INNER JOIN tableb ON
tablea.columna = tableb.columna) INNER JOIN tablec ON
tableb.columnb = tablec.columnb

Note that the challenge is in arranging the parentheses and where you put things relative to them. When using the JOIN clause, the first join is enclosed in parentheses and lists the first table name before its INNER JOIN keyword. The second join has no parentheses and DOES NOT list a table before the INNER JOIN. Instead, the first join can be thought of as the "table" on which the second join is made.

Using the simpler syntax, the join would be:

SELECT * FROM tablea, tableb, tablec
		WHERE tablea.columna = tableb.columna
		AND tableb.columnb = tablec.columnb

You could join more tables, but the performance impact should be seriously considered.


Emulating a "Words" Function

Though CF provides many string functions, one common one that it doesn't offer is a "words" function, to count the number of words in a string.

This can be easily emulated, with:

<CFSET words = ListLen ("string to count", " ")>

For the above CFSET, "words" would be set to 3. Kind of nifty.

Tips Contents:

| Home | ColdFusion | Articles | Presentations
| User Groups | Other Resources | Press Releases | Company

© 1998-2024, Charles Arehart, SysteManage
Our Practice Makes You Perfect