CASE vs IF..ELSE

  • Hi, Perhaps it's all the switching between vbscript, javascript, and T-sql but I keep getting stymied by how I think CASE should work.

    For example:

    select case iValue

             when >1 and <= 5 then 1

             when >5 and <= 10 then 2

             when >10 and <= 15 then 3

    Line 2: Incorrect syntax near '>'.

    trying the same thing with if..else gives me a similiar error

    if @days <= 1 goto HOURS

    if @days > 1 and <=21 goto DAYS

    if @days > 21 and <=90 goto WEEKS

    if @days > 90 goto MONTHS

    Line 9: Incorrect syntax near '<'.

    Are both these conditionals only able to determine equality and not a comparison?

    Dave

     

     

    Dave

    Trainmark.com IT Training B2B Marketplace
    (Jobs for IT Instructors)

  • select case

             when iValue>1 and iValue<= 5 then 1

             when iValue>5 and iValue<= 10 then 2

             when iValue>10 and iValue<= 15 then 3  end as data

    if @days <= 1 goto HOURS

    if @days > 1 and @days <=21 goto DAYS

    if @days > 21 and @days <=90 goto WEEKS

    if @days > 90 goto MONTHS


    * Noel

  • Yup thanks, I was moving my code from T-sql into the script portion and realized my brain fart...thanks

    dave

    Dave

    Trainmark.com IT Training B2B Marketplace
    (Jobs for IT Instructors)

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

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