• kevmck (7/30/2012)


    Basically - I need to match the person to the tier based on some user defined rules. These rules would be along the lines of tier 4 is only available to children aged 4-8 who have brown hair. Now lets say that someone creates tier 5 which only has the rule 'has brown hair' - if we got a 6yr old with brown hair enrolled, 2 tiers should be returned to the user, and they'd need to actually choose which is the correct one.

    However, if only 1 match was to come up, then the tier would be automatically assigned. If no matches are returned, then I'll display a message to the user because either they messed up their rules, or the participant shouldn't be enrolled in the first place, then I'd just allow them to choose from any of the tiers and send an email to the coordinator to look into it.

    The point of this is to reduce the amount of misfiled tiers to the participants - for example - a user could assign tier 4 to a participant who is 12 yrs old despite the fact that tier 4 is only for children aged 4-8 yrs. This leads to all kinds of data issues further down the line from a business standpoint - nobody may notice this for 6 months, and by then its too late to have the participant redo all the tasks assigned with their correct tier, and the data we do have is worthless because it doesn't match tier 4 criteria.

    I'm thinking I may need to rework the table design, but I'm not sure the best way to do that and still have it open ended enough that if I wanted to include some new table to be used in the rules, I don't want to have to recode everything.

    So you need an iTVF or something along those lines? What are the parameters and such. Keep in mind I am intimate with this project like you are. I am still trying to figure out what you are trying to do. I am afraid that at some point all you will want to do is slit your wrists. Dynamic sql and a lot of it is going to become your best friend. In effect you have a modified EAV type of design with these rules.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/