Home Forums SQL Server 2008 SQL Server Newbies I have written a Stored Procedure having 3 nested while loops in it .This is Working fine and I am getting desired result as I have tested this on small set of data ,but while running on large set of records it taking huge of amount of time, might be due to multiple nested while looping . Co RE: I have written a Stored Procedure having 3 nested while loops in it .This is Working fine and I am getting desired result as I have tested this on small set of data ,but while running on large set of records it taking huge of amount of time, might be due to multiple nested while looping

  • The description od what is calculate says number of times a city is visited is calculated; the sample data and expected results are completely different from this; for example a city which is visited only once has result M2, another also visited only once has result M1, and another visited only twice has result M3. Looking at the date provided field in the sample data, and guessing that the till date (which isn't specified in the sample data) is somewhere around the end of the calendar year in which the last visit occurs, it appears that M1 means city first visited during the year ending till date, M2 means first visited in the year before that, and M3 means earlier than M2, which bears no resemblance to the verbal description. Assuming the table structure is something sane, rather than having different number of columns in different rows as suggested by the sample data (that 1 in the first row is a customer id, absent in the second third and fourth rows, isn't it?) it is trivial, assuming that the actual requirement matches either the verbal description or the sample data and results, to write a single SQL statement which will do the job rather more quickly that 3 nested loops, but as the sample data and results contradict the verbal description it is not in the least bit clear which the code should do, or indeed whather it should do something else altogether.

    Tom