How Can I Check A Number To See If Its A Multiple Of Another Number?

  •  

    for instance, i want a query to take a different course depending on whether a number passed to it is even, odd, or a multiple of 3.  how would you check for this?

  • declare @x int

    set @x = 54321

    if @x % 2 = 1  -- odd

       print 'Odd'

    else -- even

       print 'Even'

    if @x % 3 = 0  -- divisible by 3

       print 'Divisible by 3'


    Cheers,
    - Mark

  • thanks!  that's just it

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

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