result set manipulation

  • hello all,

    i have a query in the following format:

    select top 1

    'xxx = ' + CONVERT(CHAR(23), startTime,121)

    from Table1

    order by startTime desc

    As you can see, the result is presented with a string ("xxx") and then the value is displayed.

    The problem I have is that if there are no entries in the table, nothing is returned, but I would like to have the following result in this case:

    "xxx = none"

    I would like the sql to do this, and not some code manipulation in my application.

  • hi, not to worry, solved my own problem and will share the solution with those interested:

    declare @date varchar(128)

    set @date = select top 1 startTime from table_name order by StartTime asc

    select

    case

    when @date <> '' then 'date = ' + @date

    else 'date = none'

    end

    and that is all folks!

    :hehe:

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

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