Professional Web Applications Themes

SQL help - Microsoft SQL / MS SQL Server

I have seen this done before but I'm blanking on how. Can anybody help me out? I have data similar to: Plan Type Comments A Emergency Notify everyone A Non-Emergency Notify manager B Emergency Call in person B Non-emergency Write email and I want the result set of a query like: Emergency Non-emergency A Notify everyone notify manager B call in person write email...

  1. #1

    Default SQL help

    I have seen this done before but I'm blanking on how. Can
    anybody help me out?

    I have data similar to:

    Plan Type Comments
    A Emergency Notify everyone
    A Non-Emergency Notify manager
    B Emergency Call in person
    B Non-emergency Write email

    and I want the result set of a query like:

    Emergency Non-emergency
    A Notify everyone notify manager
    B call in person write email
    Andrea Guest

  2. #2

    Default SQL HELP

    Here is my data

    ID DATE T1 T2 T3
    100 01/01/2003 1 0 0
    200 01/01/2003 1 0 0
    300 01/01/2003 1 0 0
    100 01/01/2003 0 2 0
    200 01/01/2003 0 2 0
    300 01/01/2003 0 2 0
    100 01/01/2003 0 0 3
    200 01/01/2003 0 0 3
    300 01/01/2003 0 0 3
    100 02/01/2003 4 0 0
    200 02/01/2003 4 0 0
    300 02/01/2003 4 0 0
    100 02/01/2003 0 5 0
    200 02/01/2003 0 5 0
    300 02/01/2003 0 5 0
    100 02/01/2003 0 0 6
    200 02/01/2003 0 0 6
    300 02/01/2003 0 0 6


    I want an output
    ID DATE T1 T2 T3
    100 01/01/2003 1 2 3
    200 01/01/2003 1 2 3
    300 01/01/2003 1 2 3
    100 02/01/2003 4 5 6
    200 02/01/2003 4 5 6
    300 02/01/2003 4 5 6

    ie group by ID, month(date), year(date)

    Thx In Advance
    Sh


    Shamim Guest

  3. #3

    Default Re: SQL HELP

    You answered your own question:
    ....
    GROUP BY ID, MONTH(date), YEAR(date)

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --



    David Guest

  4. #4

    Default SQL HELP

    You can try this:

    select ID
    , DATE
    , SUM(T1)
    , SUM(T2)
    , SUM(T3)
    from YourDate
    group by ID, DATE


    Edgardo Valdez
    MCSD, MCDBA, MCSE, MCSE+I
    Database Administrator
    http://www.edgardovaldez.us/
     
    T3 
    0 0 
    0 0 
    0 0 
    2 0 
    2 0 
    2 0 
    0 3 
    0 3 
    0 3 
    0 0 
    0 0 
    0 0 
    5 0 
    5 0 
    5 0 
    0 6 
    0 6 
    0 6 
    T3 
    2 3 
    2 3 
    2 3 
    5 6 
    5 6 
    5 6 
    Edgardo Guest

  5. #5

    Default SQL Help

    I might be missing something, but I don't see
    order_detail_org in the query. You are doing an inner
    join to itself on identical fields, so you will always get
    everything.
     

    Terry Guest

  6. #6

    Default Re: SQL Help

    Try this...

    select *
    from order_detail_chg b
    where not exists(select *
    from order_detail_org a
    where o.left(a.order_num, 11) = left(b.order_num, 11)
    and a.order_line_num = b.order_line_num)
    order by b.order_num, b.order_line_num

    --
    -oj
    RAC v2.2 & QALite!
    http://www.rac4sql.net


    "Yaheya Quazi" <edu> wrote in message
    news:023a01c3507f$6d556ed0$gbl... 


    oj Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139