ifrange
Use the ifrange
command in situations where you simply want to know whether a numerical field
is within a certain range of numerical values.
The "ifrange" syntax is:
%%
ifrange tablename.numfield
numvalue1a numvalue1b "content1"
numvalue2a numvalue2b "content2"
. . .
"defaultcontent"
%%
How it works: for each individual recipient, the command looks in the table tablename
for the field numfield
. If the field's numerical value is between numvalue1a
and numvalue1b
,
then the command prints content1
and ends the script. (Note that it also prints the content,
if the field value is equal to one of the range. If the field's numerical value is between numvalue2a
and numvalue2b
, then the command prints content2
, and so on. You can have as many value--content
groupings as you like -- but make sure each value has a content result.) If the field is not equal to
any of the values, the script prints defaultcontent
.
Example 1
Having opened a new store in Oakland and Miami, Testco wants to add a special notice in their regular
newsletter to all local customers. Testco stores zip code information in the zip
field in the
address
database table. Notice that, because zip codes can be discontinuous, you may wish to repeat
content with different blocks of zip codes.
%%
ifrange address.zip
33122 33196 "Come see our Miami
store!"
94601 94613 "Come see our Oakland
store!"
94619 94621 "Come see our Oakland
store!"
"We're opening new stores all
the time!"
%%
Joe, who lives in zip code 94605, would see:
Come see our Oakland store!
Dennis, who lives in zip code 33128, would see:
Come see our Miami store!
Tenzing, who has no zip code information, would see:
We're opening new stores all the time!
Example 2
In a direct mail campaign, you want to add a notice telling students and seniors about special discounts available to them. You already have information on their age stored in the members_ table.
%%
ifrange members_.age
13 23 "Special for students:
20% off!"
60 120 "Special for seniors:
30% off!"
"
%%
While ifrange does not support greater or less than, it is easy to create a range which would include everyone above a certain number by simply fixing one value to be extremely high or low. For example, no one is likely to be older than 120, so you can indicate "60 or older" by simply making the range limits 60 and 120.
Joe, who is 20, would see:
Special for students: 20% off!
Tenzing, who is 70, would see:
Special for seniors: 30% off!
Dennis, who is 40, would see nothing, since defaultcriteria is blank.