Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3439 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I've written a SQL query that is returning a list of data for me. I've got more than one roq, seperated by a Return. I'd like to take the different fileds out into some fields in a table.

This bit I've managed to do with the use of left/right/middle/position.

 

So in the example below. $$LLData, I've gotten 13 and 1 out into 2 different fields. When I try take 2 out it is giving me 2 13|2|1 as it's not seeing the second 13|2|1 as a seperate record.

Can someone let me know howI can get Filemaker to see this as 2 rows so I can loop through the list to pull the data into a table.


TIA.

ListLooping.thumb.png.f5c3f0d6e55442aa6f

 

Posted (edited)

You'll need to write two loops.

Assuming you have $$LLData with ¶ as record delimiter, and | as field delimiter**, write a script along these lines:

Set Variable [ $rowCount ; ValueCount ( $rowCounter ) ) ]
Set Variable [ $rowCounter ; 0 ) ]

Loop
  # [ through rows/records ]
  Exit Loop if [ Let ( $rowCounter = $rowCounter + 1 ; $rowCounter > $rowCount ) ]
  Set Variable [ $currentRow ; GetValue ( $$LLData ; $rowCounter ) ]
  # [ convert current row into a list so you can use GetValue() ]
  Set Variable [ $currentFieldList ; Substitute ( $currentRow ; "|" ; ¶ ) ] 
  Set Variable [ $fieldCount ; ValueCount ( $currentFieldList ) ]

  # [ never forget this one! ]
  Set Variable [ $fieldCounter ; 0 ) ]
  Loop
    # [ through fields ]
    Exit Loop if [ Let ( $fieldCounter = $fieldCounter + 1 ; $fieldCounter > fieldCount ) ]
    Set Variable [ $currentFieldValue ; GetValue ( $currentFieldList ; $fieldCounter ) ]
    # [ do something with $currentFieldValue, e.g. Set Field[] if you created New Record[] in the outer loop, etc. ] 
  End Loop
End Loop

Knowing your Left(), Right() and Middle() is a good thing, but as you can see, there are sometimes easier methods for text parsing and extraction.

**Make sure you specify delimiters that don't appear in your result. You could also write a Custom Function like “SQLFieldDelimiter” that simply defines a string like "§§§§" to use (consistently) as field delimiter. Then write

ExecuteSQL ( query ; SQLFieldDelimiter ; ¶ /* default anyway */ )

and in the script

Set Variable [ $currentFieldList ; Substitute ( $currentRow ; SQLFieldDelimiter ; ¶ ) ]

Edited by eos
Posted

Depending on what you are doing with the data, this may be a good candidate for the Virtual List.

This topic is 3439 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.