exclude BIT column from the Group By clause

  • Hello All,

    I have a query which is returning columns in various datatypes. this query uses the group by clasue for aggregation. I know i can get the max value that are not specified in the group by clause. But this doesn't work with BIT column.

    So, is there a way to return the bit columns along with other columns and not have it in the group by clause?

    Thank you in advance for your quick response...

  • If you cast it to a numeric type (tinyint) you should be able to use MAX.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • You could convert it to integer to use it for aggregation:

    MIN(CAST(YourBitCol AS TINYINT))

    or the lazy-dev version:

    MIN(YourBitCol + 0) -- force an implicit conversion

    Edit: @Gail: the echo was not intentional...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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