Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Unanswered: Pseudocode to SQL stored proc math operation

    How do i implement this pseudocode in a SQL stored proc?

    In my stored proc, intDS and intSS are the corresponding locally declared variables: @cnt1 and @cnt2 (both are int's).

    double intRating = 0;
    if (intDS != 0)
    intRating = ((intDS - intSS ) / intDS) * 100;
    if (intRating < 0)
    intRating = 0;
    intRating = RoundUpDown(intRating);

    The last line should round up or downd the decimal value, if it has decimals, to the next round/whole number... e.g. 28.4352635 to 28.

    Thank you!

  2. #2
    Join Date
    Nov 2002
    Posts
    272
    I'd say the Round() function does what you want. Look it up in BOL and tell us if that works for you, or why not.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    47
    something like this
    Code:
    if (@intDS <> 0)
        select @intRating = ((@intDS - @intSS ) * 100.0 / @intDS) 
    select @intRating
    
    if (@intRating < 0)
    begin
        select @intRating = round(@intRating, 0)
    end
    -----------------
    KH


Posting Permissions

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