Today, I’d like to introduce the new XData family of functions. Although these functions will be perfected and used later in higher level tools, they can be put to profit right now by advanced user to fetch any data from the database.
XData, XDataLookup and XDataCondition were introduced in version 2.9.9 of XLGL. XData is used to fetch data from database table. For example:
=XData("tCustomr", "sName", 1)
will return the name of the first customer in the database. The field name can be replaced by expression, such as:
=XData("tCustomr", "SUBSTRING(sName, 1, 5)+'.'", 1)
will return the first 5 characters of the first customer name followed by a dot (.). Aggregate functions can also be used. For example:
=XData("tCustomr", "COUNT(sName)")
will return the number of customer in the table.
You may have notice that the third argument is the index in the table of the record we want. Most of the time, you don’t know the index of the row you want. This is where XDataLookup and XDataCondition comes in.
=XDataLookup("tCustomr", "sName", "Ashburton Reinforcing")
will return the index of the customer named Ashburton Reinforcing, which can then be used in the XData function to retrieve other information on that customer:
=XData("tCustomr", "sCity", XDataLookup("tCustomr", "sName", "Ashburton Reinforcing"))
Of course, you can put both function in difference cells and reference them.
Sometime XDataLookup will return more than one index. For example:
=XDataLookup("tCustomr", "sCity", "Richmond")
will return the index of all the customer whose reside in Richmond. You can then get a count of these by using:
=XData("tCustomr", "COUNT(sName)", XDataLookup("tCustomr", "sCity", "Richmond"))
XDataCondition returns indices in the same manner but using any custom condition. For example:
=XDataCondition("tCustomr", "sName LIKE 'A*'")
will return the indices of all all customer that have a name starting with A.
In an upcoming post, we’ll look at how to use the XData family of function to create your own powerful worksheet functions.