sql help for case statement

  • Hi, I need to do a sql use case, but I keep on getting syntax errors.

    What I want to do is test an int value, if it is great than 7, then return 'Yes', if less than 7, then return 'No'

    Here is my code:

    declare @mv_int int

    declare @mv_char varchar(10)

    set @mv_int = 8

    select @mv_char =

    case @mv_int > 7

    when 1

    then 'Yes'

    when 0

    then 'No'

    end

    print @mv_char

    It complains that incorrect syntax near '>'

    Any idea about how to achieve this ?

    Thanks.

    Abby

  • When checks for a true statement. Case is more like a SELECT statement in VB. This will work for you.

    CASE

    WHEN @mv_int > 7 THEN 'Yes'

    ELSE 'No'

    END

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Another possibility:

    declare @mv_int int

    declare @mv_char varchar(10)

    set @mv_int = 8

    if @mv_int >7

    select @mv_char ='Yes'

    else

    select @mv_char ='No'

    select @mv_char

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

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