• richard.noordam (11/27/2012)


    What is the best way to deal with a set of rows and determine/return the first occurance of a non-zero column value in each row, using a set of column fields that are determined at runtime?

    In my opinion best practice here would be to do the least clever option.

    That said, doesn't it really depend on how responsive you need your system to be? Ie., if a new column appears, would you like your code to immediately change to adapt, or will hand editting a routine be enough?

    I have a routine that checks for column additions or changes for a few tables but it doesn't do much more than alert me to the fact I need to update a few routines. I could make it dynamic of course, but I worry about leaving the company with too much "clever" programming. It might be a borderline concern.

    On the other hand, I have a system I threw together with m4 the macro processor that I can supply a server name, database name, network share, and it produces a hardwired set of backup routines, I actually did it that way because we like nice static backup t-sql routines but I got tired of doing the manual edits for each new database.

    There should be a 'best-practice' on this, i would think, maybe not.

    in any case.... there should be a pattern of behavior in assessing and attempting to solve, that doesn't rely on specific data.

    I've never had much luck discussing interesting and maybe generalized topics here and have for the most part just decided to stick with answering a few posts now and then, but maybe you'll fare better. Best of luck in any case!