Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

RequestSQL ( fieldDesired ; fieldKey ; valueKey )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.0  (38 votes)
  Discuss this Custom Function

hisc, no company
http://nowebsite.com

retrieves value from one field base on value of another field

Sample Input:
RequestSQL(customers::name;customer::CustomerID_pk;45)

///

RequestSQL(customers::phone;customer::name;"Dude")
Sample Output:
the name of the customer whose ID_pk is 45

///

the telephone of all the customers whose name is "Dude"


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

this custom functions allows you to retrieve a value from any table, based on a search. One will put the field from which they desire the value – fieldDesired –, the field which will be used as a criteria for finding the right record, from all the existing records – fieldKey – and the value that the fieldKey must have for the desired value to be returned – valueKey

*updated so that it works with number values also, without need to declared that field is number

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 8 comments

See here:

Let ( [
nameFieldDesired = GetFieldName ( fieldDesired ) ;
nameFieldKey = GetFieldName ( fieldKey ) ;
nameFieldDesired_list = Substitute ( nameFieldDesired ; "::" ; ¶ ) ;
myTable = GetValue ( nameFieldDesired_list ; 1 ) ;
fieldDesired_sql = GetValue ( nameFieldDesired_list ; 2 ) ;
fieldKey_sql = GetValue ( Substitute ( nameFieldKey ; "::" ; ¶ ) ; 2 ) ;
fieldType = ExecuteSQL ( " SELECT * FROM FileMaker_Fields WHERE TableName = '" & myTable & "' and FieldName = '" & fieldKey_sql & "'" ; "" ; "" ) ;
condSingleQuote = Case ( PatternCount ( fieldType ; "varchar" ) ; "'" ) ;

~sql = "SELECT " & Quote ( fieldDesired_sql ) & "
FROM " & Quote ( myTable ) & "
WHERE " & Quote ( fieldKey_sql ) & "
= " & condSingleQuote & valueKey & condSingleQuote

] ;

ExecuteSQL ( $$~sql ; "" ; "" )
)

eos, Teg
August 11, 2014 1:32am

eos, I believe it works, but does it have any improvement over the standard function?
I see you changed my way of approach on getting names (Substitute and GetValue instead of Position, which seems more reasonable) and also the way to get the fieldType (which is a best name them valueType, I have to admit), but does it add new functionality?

(If it is about the fieldKey being a number, I have recently updated it).

Anyway, I'm glad to see how you'd do, and I'll probably change a little in latter development.

hisc, sao paulo/BR
August 12, 2014 3:01am

New functionality is for the end user; from a developers point of view, it's written more clearly without repetitions; e.g. why set a flag that you then have to read two times to set a value that you could have calculated in the first place?

eos, Teg
August 12, 2014 8:21am

I agree with you. And I thank you for the time on perfecting and explaining. I'll update it.

hisc, sao paulo/BR
August 12, 2014 1:54pm

I had a number valueKey with dashes in it. It didn't work until I added GetAsNumber(valueKey). I simplified the use of need_quotation_sql slightly.

need_quotation_sql = If(fieldType="Number"; False;True)
];
ExecuteSQL(
" SELECT \""&
fieldDesired_sql
&"\" FROM \""&
myTable
&"\" WHERE \""&
fieldKey_sql
&"\"="&
If (need_quotation_sql=True; "'" & valueKey & "'"; GetAsNumber(valueKey) )
; "" ; ""
)
)

Eric, San Jose, CA
January 19, 2015 12:38pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 7 + 8 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions