select with 2 diffrent condition in one column

  • Hi friends,

    I have a table named Record with three column :

    ID int pk

    Tone int

    Duration int

    IsIncomming bit

    i want to select sum of duration of records with IsIncomming=1 And records with IsIncomming=0 as one result ( one row with 2 columns ),how can i do this ?

    SELECT Tone,SUM(Duration) FROM Record Group By Tone Where IsIncomming=1

    above TSQL command return just records with isIncomming=1 but i need to select both in a row

    Thanks

  • Hi there, you need a cross-tab query

    SELECT

    Tone,

    SUM(CASE WHEN IsIncomming=1 THEN Duration ELSE 0 END) AS [IsIncomming = 1],

    SUM(CASE WHEN IsIncomming=0 THEN Duration ELSE 0 END) AS [IsIncomming = 0]

    FROM Record

    Group By Tone

    ///Edited syntax error

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

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