| 
                
Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | SadhuStarting Member
 
 
                                        14 Posts | 
                                            
                                            |  Posted - 2015-01-07 : 01:42:37 
 |  
                                            | I have a Query given below that gives the result of top five Units for that edit date. Now I need to add a COlumn CHANGE to the result set that compares the values from Previous date and specify if the value has Increased or decreased.Query : DECLARE @LoBId AS INT = 3;SELECT TOP 5      BuName       ,SUM(CAST(FlaggedForResponse AS INT)) FlaggedEdits      ,SUM(CASE WHEN FlaggedForResponse = 0 THEN 1 ELSE 0 END) NotFlaggedEdits      FROM CancelCorrect.Amend WHERE EditDate = '2014-12-29 00:00:00.000'AND LoBId=@LobIdGROUP BY       BuNameORDER BY FlaggedEdits desc,NotFlaggedEdits descOutput Of the above :BuName	| FlaggedEdits | NotFlaggedEditsVANILLA IR SWAPS - EMEA,	28,	1BAC AMRS FX PRIME BROKERAGE,	22,	6BAC AMRS FX MANAGEMENT,	20,	2,AMERICAS G10 - FX OPTIONS,	12,	0AUS SWAP TRADING,	8,	0Desired Output :BuName	| FlaggedEdits | NotFlaggedEdits | ChangeVANILLA IR SWAPS - EMEA,	28,	1,    IncreasedBAC AMRS FX PRIME BROKERAGE,	22,	6,    SameBAC AMRS FX MANAGEMENT,	        20,	2,    DecreasedAMERICAS G10 - FX OPTIONS,	12,	0,    IncreasedAUS SWAP TRADING,	        8,	0,   Increased |  |  
                                    | djj55Constraint Violating Yak Guru
 
 
                                    352 Posts | 
                                        
                                          |  Posted - 2015-01-07 : 11:55:47 
 |  
                                          | Group by date and buname using CTE then get top five and compare to previous daydjj |  
                                          |  |  |  
                                |  |  |  |  |  |