Can anyone help group this query result? Thanks.

  • I have a cte:

    With cte as

    (

    Select distinct Incident_ID,

    ACTUAL_SEVERITY ,

    Policy

    From

    table)

    There are 3 ACTUAL_SEVERITY value: 1-High, 2-Medium and 3-Low

    I need the final result be like:

    Policy High Medium/Low

    How do I write the script with out using temp table or cursor? Can anyone help? Thank you very much.

  • Sounds like you just need to use PIVOT...can't be 100% sure though without some sample data/output.


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • yb751 (6/4/2015)


    Sounds like you just need to use PIVOT...can't be 100% sure though without some sample data/output.

    Thanks, never used pivot before, can you help?

  • Please post DDL (CREATE TABLE statement) for the table(s) involved, some sample data for the table(s) involved (INSER INTO statements), and the expected results based on the sample data you provide.

  • halifaxdal (6/4/2015)


    yb751 (6/4/2015)


    Sounds like you just need to use PIVOT...can't be 100% sure though without some sample data/output.

    Thanks, never used pivot before, can you help?

    If it is indeed what you need I'll be more than happy to provide an example. 😉 However, as I hinted to and Lynn has mentioned we need some sample data and what you expect to see. Providing column names is only half of what we need. I know often folks are reluctant to post confidential data which is perfectly understandable. In those case just make up some values.

    Cheers,


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • Or you could read the following article and learn how to do it yourself, either with pivot or cross tabs.

    http://www.sqlservercentral.com/articles/T-SQL/63681/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks to all replies, I will come back once I am out of some other issues

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

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