Results 1 to 9 of 9

Thread: Looping through a result set

Threaded View

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Looping through a result set

    SQL Server 2008
    I need to loop through a result set n times and calculate percentages.

    Lets say my result contains one field and looks like :
    Code:
    Field1
    =====
    2
    2
    1
    0
    Lets say that my parameter "n" = 3.
    I must loop through the result set and calculate what the percentages are for the numbers 1 through 3 and return these.
    In the above example I would get
    One = 25%, Two = 50%, 3= 0%, Unknown = 25%.

    I have been looking at this all day and for the life of me cannot figure out how to achieve it .

    Any help would be much welcomed.
    Last edited by venerable bede; Apr 11th, 2012 at 05:59 AM.

    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width