Tuesday, 6 December 2016

SQL Group With Group Total

  1. SELECT isnull(WO_status,0) as WO_status,          
  2. (case  when MwO.WO_status=1 then 'Open' when MwO.WO_status=2 then 'Close' when MWO.WO_status=3 Then  'Short Close'          
  3. when MwO.WO_status=4 then 'Cancel'          
  4.  else 'Total' endas statusR,          
  5. count(*) as countValue                            
  6. FROM   M_WorkOrder MwO                         
  7.  inner join    M_WorkorderDetails MwOd  on MwO.WOID=MwOd.WOD_WOID                                                        
  8. INNER join BILL_KEYWORD BK  on BK.id=MwOd.WOD_KEYID                                                        
  9. INNER join billing_from bf      on bf.id=MwO.WO_CID                               
  10.  where  (MwOd.WOD_CUserID=15 or 15 =0 )              
  11.  group by WO_status  WITH ROLLUP

No comments:

Post a Comment

SQL Server: Make all UPPER case to Proper Case/Title Case

CREATE FUNCTION [dbo].[fnConvert_TitleCase] (@InputString VARCHAR(4000) ) RETURNS VARCHAR(4000) AS BEGIN DECLARE @Index INT DECLARE @C...