Skip to content

Instantly share code, notes, and snippets.

@hkilter
Created November 17, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkilter/255b8be371fb4c8d59ffb2c8537449c8 to your computer and use it in GitHub Desktop.
Save hkilter/255b8be371fb4c8d59ffb2c8537449c8 to your computer and use it in GitHub Desktop.
How to put content from multiple databases in one table using datatool?
%% https://tex.stackexchange.com/questions/117747/how-to-put-content-from-multiple-databases-in-one-table-using-datatool
\documentclass{article}
\usepackage{datatool}
% generate first test database
\begin{filecontents}{first.csv}
Year,Number
2001,10
2002,20
2003,30
2004,40
\end{filecontents}
% generate second test database
\begin{filecontents}{second.csv}
Year,Number
2001,101
2002,202
2003,303
2004,404
\end{filecontents}
\DTLloaddb{first}{first.csv}
\DTLloaddb{second}{second.csv}
\begin{document}
% append second column of second data base to first data base
\newcount\rowIdx
\dtlforcolumn{\secondNumber}{second}{Number}%
{%
% iterate through each entry in the `Number' column of the second database
\advance\rowIdx by 1\relax
% get corresponding row of first database
\dtlgetrow{first}{\rowIdx}%
% append to current row (this new column is assigned the key `Number2')
\dtlappendentrytocurrentrow{Number2}{\secondNumber}%
% update first database
\dtlrecombine
}
\DTLdisplaydb{first}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment