sql server - How to combine these 2 queries in sqlserver -


how combine below 2 sqlserver queries

select count(dept) totaldept  employee datepart(mm,joindate) = datepart(mm, dateadd(mm, -1, getdate())) , datepart(yyyy, joindate) = datepart(yyyy, dateadd(mm, -1, getdate())) group (datename(month,joindate)+' , '+datename(year,joindate))  select count(*) employee group dept 

try 1 -

select        totaldept = count(dept)      , gr.grouped_by_dept employee cross join (     select grouped_by_dept = count(1)     employee     group dept ) gr datepart (mm, joindate) = datepart (mm, dateadd(mm, -1, getdate()))     , datepart (yyyy, joindate) = datepart (yyyy, dateadd(mm, -1, getdate())) group datename (month, joindate) + ' , ' + datename (year, joindate) 

update:

declare @firstdayofmonth datetime select @firstdayofmonth = dateadd(day, -(day(getdate()) - 1), getdate())  select        t2.monthyear     , t2.[system]     , t3.[countbysystem]     , newaddr = count(t2.[address]) (     select            monthyear = datename(month, dateinserted) + ' , ' + datename(year, dateinserted)         , t.[system]         , t.[address]     dbo.testtable t     dateadd(day, -(day(t.dateinserted) - 1), t.dateinserted) = @firstdayofmonth ) t2 join (     select            t2.[system]         , [countbysystem] = count(1)     dbo.testtable t2      group t2.[system] ) t3 on t2.[system] = t3.[system] group        t2.monthyear     , t2.[system] order newaddr 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -