Case statments that return values from a table

  • I am trying to migrate Access SQL to T SQL.

    I am migrating IIF staements using case statements .. I have encountered a problem in that some of the IIF clausew return a value from a column value as opposed to

    a 1 or a zero T SQL doesn't seem to be allowing me to do this.

    Any advice appreciated .

  • I have done a similar thing migrating Foxpro to t-SQL.

    I assume you mean:

    declare @Foo int

    set @Foo=4

    select case when @Foo>3 then 'more than 3' else 'less than 3' end

    Some CASE statements can get hair-raisingly complicated if you have calculations conditional on results!!

  • You can return any column value as a result from the case statement, just like you're doing constants now. For example,

    Select col1, case when <some boolean condition>

    then

    col2

    else

    col3

    end as <somename>, col4, ...

    Jay


    Jay Madren

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

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