3

Given a test.csv file w/ the content:

"BILL TO EMAIL"
"test@att.net"
""
"test.test@test.org"
"test.test@test.org"

Processing it w/ datatool in xelatex w/:

\documentclass{memoir}
\usepackage{datatool}
\DTLloaddb{data}{test.csv}
\begin{document}
\DTLforeach*{data}{\billtoEM=BILL TO EMAIL}{\billtoEM"\DTLifnull{\billtoEM}{N}{Y}"\par}
\end{document}

results in:

test YYYYY

How do I get the test to evaluate to N for the second record?

0
5

There's a difference between null and empty values (in a similar way to programming languages "" != null). If you load data from a CSV file, missing values are empty. (There is a blank value in that column for that row.) Null values can occur when constructing a database where values for a column or columns aren't assigned. (For example, defining data using \DTLnewdb or pulling data from SQL using datatooltk.)

You can test for empty values using etoolbox's \ifdefempty:

\documentclass{memoir}
\usepackage{datatool}
\DTLloaddb{data}{test.csv}
\begin{document}
\DTLforeach*{data}{\billtoEM=BILL TO EMAIL}{\billtoEM"\ifdefempty{\billtoEM}{N}{Y}"\par}
\end{document}

Alternatively you can use \DTLifnullorempty that tests for null or empty values.

Further details in 5.5 "Null Values" of the datatool user manual.

2
  • Thank you for your patience, and please accept my apologies for not finding that command in the manual.
    – WillAdams
    Nov 24 '15 at 17:26
  • @WillAdams That's okay. It's quite a common mistake. I ought to add it to the datatool faq. Nov 24 '15 at 17:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.