Efficient way to determine if a criteria is met

  • Hi, I am trying to find out an efficient way to determine if employee meets a criteria. We have employee table that has following information

    Company, Empno, Level1, Level2, Level3, Level4, Level5

    we have criteria table as follows

    GridId Type TypeValue NextGridId

    0001 Level1 ABC 0002

    0002 Level2 123 0003

    0003 Level3 A12 0004

    So, I wrote a scalar value function to loop through each record and if employee has TypeValue in the employee table for all the records in the criteria table, the employee meets the criteria.

    But if I want to do this for say 100 employees, it is not efficient to call the function for each employee. Any ideas on how to make it efficient?

    Thanks,

    Sridhar.

  • Sridhar-137443 (2/19/2015)


    Hi, I am trying to find out an efficient way to determine if employee meets a criteria. We have employee table that has following information

    Company, Empno, Level1, Level2, Level3, Level4, Level5

    we have criteria table as follows

    GridId Type TypeValue NextGridId

    0001 Level1 ABC 0002

    0002 Level2 123 0003

    0003 Level3 A12 0004

    So, I wrote a scalar value function to loop through each record and if employee has TypeValue in the employee table for all the records in the criteria table, the employee meets the criteria.

    But if I want to do this for say 100 employees, it is not efficient to call the function for each employee. Any ideas on how to make it efficient?

    Thanks,

    Sridhar.

    I think we need more info here.

    The link between your two tables is unclear.

    Please post DDL, sample data and desired results as per the link in my signature.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • A Table-Valued function would be much more efficient than a scalar function. I agree we need a bit more information on how your tables are related.

  • I would add to this that we'll probably need to know what values are stored in the Leveln columns of the employee table.

    DDL and consumable sample data (INSERTs) would probably get you a tested solution rapidly.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply