How to columns are showing the row side

  • Hi All,

    How to columns are showing into row for example ...

    nboothcode KANDRU KAMALA DURU VIJAY KUMAR DONTHIREDDY SRINIVASA KUMARI MUNAGAPATI VENKATESWARA RAO MUPPALLA NAGESWARARAO

    1 447 11 217 10 71

    2 318 3 60 7 112

    3 324 3 40 1 86

    4 411 10 221 3 98

    5 462 12 185 10 128

    6 251 4 195 3 16

    7 199 0 86 5 19

    8 263 0 101 8 33

    9 250 2 176 9 36

    10 174 1 71 3 34

    11 239 3 95 9 33

    12 214 5 117 2 42

    13 155 1 178 4 34

    14 184 4 197 6 37

    15 273 4 140 10 75

    16 328 6 124 21 60

    17 249 6 188 4 29

    18 254 4 281 8 45

    but i want

    nBoothCode Names Votes

    1 KANDRUKAMALA 447

    1 DURUVIJAUMAR 217

    1 DONTHIREDDYRINIVASAMARI 10

    1 MUNAGAPATENKATESWARAAO 71

    how to write

  • Hi,

    this is simple PivotTable statement

    try this

    create table #temp

    (

    nboothcode int,

    [KANDRU KAMALA] int,

    [DURU VIJAY KUMAR] int,

    [DONTHIREDDY SRINIVASA KUMARI] int,

    [MUNAGAPATI VENKATESWARA RAO] int,

    [MUPPALLA NAGESWARARAO] int

    )

    insert into #temp

    select 1, 447, 11, 217, 10, 71

    union all

    select 2, 318, 3, 60, 7, 112

    union all

    select 3, 324 ,3, 40, 1, 86

    union all

    select 4, 411, 10, 221, 3, 98

    union all

    select 5, 462, 12, 185, 10, 128

    select a.nboothcode,

    b.col1 as 'Name',

    max(case when b.col1 = 'KANDRU KAMALA' then a.[KANDRU KAMALA]

    when b.col1 = 'DURU VIJAY KUMAR' then a.[DURU VIJAY KUMAR]

    when b.col1 = 'DONTHIREDDY SRINIVASA KUMARI' then a.[DONTHIREDDY SRINIVASA KUMARI]

    when b.col1 = 'MUNAGAPATI VENKATESWARA RAO' then a.[MUNAGAPATI VENKATESWARA RAO]

    when b.col1 = 'MUPPALLA NAGESWARARAO' then a.[MUPPALLA NAGESWARARAO] else 0 end) as 'VOTE'

    from #temp a,

    (select col1 from

    (select 'KANDRU KAMALA'col1

    union all

    select 'DURU VIJAY KUMAR'

    union all

    select 'DONTHIREDDY SRINIVASA KUMARI'

    union all

    select 'MUNAGAPATI VENKATESWARA RAO'

    union all

    select 'MUPPALLA NAGESWARARAO'

    ) as X )b

    group by a.nboothcode,b.col1

    order by a.nboothcode,b.col1

    ARUN SAS

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

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