Link to home
Start Free TrialLog in
Avatar of engineroom
engineroom

asked on

Select Case (greater than number)

hey all, how do i do something like this


num = 12

select case num

    case 10

    case > 10  <-------- greater than????


end select

I read somewhere that you could use the IS keyword, but that didn't work. Any ideas? Thanx

dj
Avatar of BubbaisBest
BubbaisBest

engineroom,

Hopefully someone can give you an exact answer but I never found anything on this when I looked for it.  So what I did was do my If-Then-Else loop and set a variable to a number. I did then did my case.  I know this is a workaround but that was the only thing I could find.

Bubs
DECLARE @intNumber INTEGER


SET @intNumber = 12


SELECT
      CASE WHEN
            @intNumber = 12
                  THEN 'Number Equals Twelve'
      WHEN @intNumber < 12
            THEN 'Number Less than Twelve'
      END
You can use a series of if.. else if... statements, but you can't do what you're trying with a CASE statement.
Here is a snipplet of my code:

If intNum<0 then
   intCase = 1
ElseIf ((intNum>=0) AND (intNum<10)) then
   intCase = 2
ElseIf ((intNum>=10) AND (intNum<100)) then
   intCase = 3
ElseIf intNum >= 100 then
   intCase = 4
End If

Select Case intCase
  Case 1
    ' do here if less than 0
  Case 2
   ' do here between 0 and 10
  Case 3
   ' do here between 10 and 100
  Case 4
   ' do here if over 100
End Select

Bubs
I got creative when seeing the question, and although plenty of alternatives have been offered, it seemed a waste not to post mine:

<%

n = 2

select case true
      case (n = 1)
            %>1<%
      case (n > 1)
            %>2<%
end select

%>
Avatar of engineroom

ASKER

neoTeg, is this right?

select case true?
ASKER CERTIFIED SOLUTION
Avatar of NeoTeq
NeoTeq

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent NeoTeq...Just what engineroom was needing (as well as myself)...Bubs
thanx, that's great!

dj