0

tl;dr: I am looking for the datatool equivalent of what, in pure SQL, would be SELECT MembershipType FROM members WHERE ID = 1.

I have a problem with datatool. I can load and loop through my db with no problem, but I need to access and check against a specific row. Consider the following MWE:

\documentclass{scrartcl}
\usepackage{datatool}
  
    \DTLnewdb{members}
    \DTLnewrow{members}%
    \DTLnewdbentry{members}{ID}{1}%
    \DTLnewdbentry{members}{Name}{Alpha}%
    \DTLnewdbentry{members}{MembershipType}{Honorary}%
    \DTLnewdbentry{members}{HasParent}{N}%
    \DTLnewrow{members}%
    \DTLnewdbentry{members}{ID}{2}%
    \DTLnewdbentry{members}{Name}{Bravo}%
    \DTLnewdbentry{members}{MembershipType}{Regular}%
    \DTLnewdbentry{members}{HasParent}{N}%
    \DTLnewrow{members}%
    \DTLnewdbentry{members}{ID}{3}%
    \DTLnewdbentry{members}{Name}{Charly}%
    \DTLnewdbentry{members}{MembershipType}{Regular}%
    \DTLnewdbentry{members}{HasParent}{N}%
    \DTLnewrow{members}%
    \DTLnewdbentry{members}{ID}{4}%
    \DTLnewdbentry{members}{Name}{Delta}%
    \DTLnewdbentry{members}{MembershipType}{Regular}%
    \DTLnewdbentry{members}{HasParent}{2}%
    \DTLnewrow{members}%
    \DTLnewdbentry{members}{ID}{5}%
    \DTLnewdbentry{members}{Name}{Echo}%
    \DTLnewdbentry{members}{MembershipType}{Regular}%
    \DTLnewdbentry{members}{HasParent}{1}%

\begin{document}

\DTLforeach{members}
{
  \ID=ID,
  \Name=Name,
  \MembershipType=MembershipType,
  \HasParent=HasParent}
                  {% begin of db foreach loop
                  \DTLifstringeq*{\MembershipType}{Honorary}{{\ID~\Name: No Payment (Honorary Member)\\}
                  }
                    {\DTLifstringeq*{\HasParent}{N}
                      {\ID~\Name: Full Payment (No Parent)\\}
                      {\ID~\textbf{\Name}: 
                      Reduced Payment (Parent = \HasParent)\\
                      }
                    }
                 } % end of db foreach loop

\end{document}

My db consists of five members:

ID Name MembershipType HasParent
1 Alpha Honorary N
2 Bravo Regular N
3 Charly Regular N
4 Delta Regular 2
5 Echo Regular 1

I have both "honorary" and "regular" members, as well as discounts for children, whose parent is also a regular (full) member. Based on the provided sample data, A. should pay nothing (=honorary) while B. and C. pay full. D. pays a reduced fee, because of parent B., but E. should pay full, since his parent A. is not a fee-paying member to begin with.

In my document, I first exclude "Honorary" members, and then check to see if \HasParent == N for all "Regular" members. This works fine, except for Echo: How can I additionally check against Echo's Parent's MembershipType? As I've said above, in SQL a simple SELECT MembershipType FROM members WHERE ID = 1 would suffice, but unfortunately I don't know how to do that with datatool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.