It took a day-and-a-half of banging my head on the desk, but I figured out how to write this damned query. Sheesh.
SQL?
Yeah. Had to select which of one or more children of a particular guardian has the birthdate closest to the guardian's enroll date.
Definitely not my forte. I was dealing with a proxy server issue. Gee, I hate Windows.
Would have been easy in a properly normalized database, or if I could just write some C# code. As it was, this was all coming from one query, and my query had to replace another query and have the same fields but return the index child correctly. So, required a self-join to an aggregate query, and one of the join conditions had to be the return value of an aggregate function. Total fuster-cluck. But I did it.
F'n index children, amiright?
And it's worth pointing out, for Tex's sake, that this is all a bunch of welfare data. Pure communist database.
What happens if they don't have a child?
Well, since this is a database of information about mothers, infants, and early childhood home visits, not having a child is not a business case I have to deal with.