How do I group by "group"?

  • I have a table to be grouped based on a field called "category"

    The category is based on categories, e.g. if the row has a category of :

    LIKE '%PII%' OR

    LIKE '%PIPEDA%' OR

    LIKE '%HIPAA%' OR

    LIKE '%Resume for HR%'

    Then the category is called "PII"

    if the row has a category of:

    LIKE '%PCI%' OR

    LIKE '%Cards%'

    Then the cagegory is called "PCI DSS"

    .....

    What I need to finally generate is group by the new categories: PII, [PCI DSS], and so on

    How do I write the script? I prefer not to use temp table, if possible.

    Thanks

  • i think you just put a case in your group, like this:

    group by

    CASE WHEN [Category]LIKE '%PII%' OR

    LIKE '%PIPEDA%' OR

    LIKE '%HIPAA%' OR

    LIKE '%Resume for HR%'

    Then 'PII'

    WHEN [Category]LIKE '%PCI%' OR

    LIKE '%Cards%'

    THEN 'PCI DSS'

    ELSE 'Default Category'

    END

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks.

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

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