Non-Sequential Insertion of Data from Temp Table or Arraylist Structure From Within Nested Loop - Inserting Values into Related Tables with Identity Key, CLR or CTE Needed

  • Perhaps you are not understanding the details of the selection process:

    If you are selecting 30 people

    out of 100 possible people (they meet the criteria)

    and the 100 is within the compiled list of 1000 people

    You have looped through the 1000 and grabbed the 100 people that meet the criteria

    T-list = 100 person list

    Out of this 100 you want to select 30

    Assumming You have pre-calculated a starting (3) and incrementing (7) number [This is a regulation for the processing of these people; you have to do this, you CANT just randomly select 30 people, nor just select first 30, the calculated 3 and the 7 are based off some criteria used for thier calculation]

    Start at the 3rd position of T-list - select every 7th name from T-list

    for ex. 3rd, 10th, 17th.... person from T-list

    If you reach the end of T-list and have not selected your full 30 people, re-calculate the starting number (now 5), and start at the 5th position of T-list, and select every 7th name

    so, select the 5th, 12th, 19th..... name from the T-list

    Also, during the 2nd iteration through the T-list,

    if you happen to select a name that has already been selected,

    skip and select the name 5 positions away from that name.......

    when you reach your goal (30 people selected from T-list) break

    I hope that clarification was not terribly confusing......

  • Does this selection method have reasoning based up Statistical Theory?

    What are the regulations/reasons for not selecting 30 random people from the 100 ?

  • Yes - Specific Instructions are given to govern the specifics on how the lists are processed, so that they may be in accordance with certain ordinances/laws (I know it sounds weird)

    The starting and increment numbers MUST be calculated in a certain way

    Does that answer your question or are you asking me HOW the start and increment numbers are calculated?

  • Tech_Newbie (6/17/2008)


    Perhaps you are not understanding the details of the selection process:

    If you are selecting 30 people

    out of 100 possible people (they meet the criteria)

    and the 100 is within the compiled list of 1000 people

    You have looped through the 1000 and grabbed the 100 people that meet the criteria

    T-list = 100 person list

    Out of this 100 you want to select 30

    Assumming You have pre-calculated a starting (3) and incrementing (7) number [This is a regulation for the processing of these people; you have to do this, you CANT just randomly select 30 people, nor just select first 30, the calculated 3 and the 7 are based off some criteria used for thier calculation]

    Start at the 3rd position of T-list - select every 7th name from T-list

    for ex. 3rd, 10th, 17th.... person from T-list

    If you reach the end of T-list and have not selected your full 30 people, re-calculate the starting number (now 5), and start at the 5th position of T-list, and select every 7th name

    so, select the 5th, 12th, 19th..... name from the T-list

    Also, during the 2nd iteration through the T-list,

    if you happen to select a name that has already been selected,

    skip and select the name 5 positions away from that name.......

    when you reach your goal (30 people selected from T-list) break

    I hope that clarification was not terribly confusing......

    Keep in mind that this is NOT what my solution is doing.... I didn't allow for the resampling scenario. I'm assuming you will have to torture it somehow.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I was just being curious, I like to find out why people are doing things in certain way in SQL queries.. This sounds like something that the Government would do...

  • To steveb - It does doesnt it?

    To Matt Miller -I am aware of that, however, I am under the assumption that i can simply encase it in a stored proc and have it return the number selected, and run it again using the number needed in order to finish the selection within a loop, and break out of it when the number of people selected reaches 30

  • Tech_Newbie (6/17/2008)


    To steveb - It does doesnt it?

    To Matt Miller -I am aware of that, however, I am under the assumption that i can simply encase it in a stored proc and have it return the number selected, and run it again using the number needed in order to finish the selection within a loop, and break out of it when the number of people selected reaches 30

    As long as you stop the "wrapping". (I built in to pull from the 3's, then the 2's and then the 1's, etc...). I didn't catch the part about "randomly pick a new base and new modulo and continue".

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I'd like to see the URL for the "regulation" that started all of this... 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 8 posts - 16 through 22 (of 22 total)

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