How can we help you today? How can we help you today?

Problem with case expression in SELECT clause

When I use Lay Out SQL on
select value,       case 
                            when datediff(yyyy, p.TransactionDate, getdate()) = 0  then sum(p.Amount)
                                end as CurrentYearValue
from   tableName

The following is the result:
select   value
        , case when datediff(yyyy, p.TransactionDate,
                             getdate()) = 0 then sum(p.Amount)
                               endas CurrentYearValue
from     tableName

Note that endas should be two words, "end as"
drsql
0

Comments

2 comments

  • drsql
    On further review, it seems to be a bug with the option:

    General, Commas, Multiple Line Statements

    The two "Space after comma" settings. When they are not checked, there will be no space between the As and the first value. For example:
    select 'hi' as fred,
           'bye' as barney
    from test
    
    is layed out as:
    select   'hi' as fred
            , 'bye'as barney
    from     test
    

    Apparenly it is removing the space from the wrong location. So the workaround is to turn on the Space after comma. Not a big deal, but it looks funny :
    select    'hi' as fred
            , 'bye' as barney
    from      test
    
    drsql
    0
  • Andras B
    drsql wrote:
    ...
    Note that endas should be two words, "end as"

    Thank you, this is a bug, quite a scary one :). It will be fixed for the final release.

    Many thanks for reporting this,

    Andras
    Andras B
    0

Add comment

Please sign in to leave a comment.