Mike Yearwood
Toronto, Ontario, Canada
General information
Title:
Reduce code article
Hi Hilmar
I finally skimmed through all the UT mags. The neatest trick of all was your ordering records bit.
SELECT ..., at(Code, "QWER") as OrderField
That can be expanded to handle multi-string codes too. Assuming code is 5 chars with no spaces...
select INT(AT("," + code + ",",",ABCDE,12345,FGHIJ,67890,") / 5 + 1) + 1 as OrderField
I believe a UDF could be made for this, making it easier to use it in several similar queries. I would not make it very general purpose as it would add significant overhead with parameter checking etc.
Something like this...
UDFCodeOrder.PRG
RETURN INT(AT("," + code + ",",",PEARS,12345,APPLE,ORANG,") / 5 + 1) + 1
With the query being
select UDFCodeOrder() as OrderField
Agreed?
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only