Author |
Topic |
vipinjha123
Starting Member
45 Posts |
Posted - 2012-05-03 : 04:10:36
|
Dear All,i want to find the number of employee joined in month and yearmy table strucure is table name:-EmpEMPID NAME DOJ LOC1000 VIP 1/1/2012 MUMBAI1200 JHA 1/2/2012 MUMBAI1300 REN 1/2/2012 MUMBAII WANT TIO FETCH HOW MANY NUMBER OF EMPLOYEE JOINED IN FEB OR SO MORE THANKS IN ADVANCE,REGARDS,vIPIN JHA |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-03 : 04:20:11
|
[code]select dateadd(month, datediff(month, 0, DOJ), 0), count(*)from EMPgroup by dateadd(month, datediff(month, 0, DOJ), 0)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
vipinjha123
Starting Member
45 Posts |
Posted - 2012-05-03 : 06:45:35
|
i modified my query as u suggested. like belowSELECT A.* FROM (select left(DATEname(mm,EMP_DATEOFJOINING),3)+'-'+right(convert(varchar,DATEPART(yy,EMP_DATEOFJOINING)),2) "Month-Year", count(*) as "Number of joined Empl"from erm_employee_mastergroup by left(DATEname(mm,EMP_DATEOFJOINING),3)+'-'+right(convert(varchar,DATEPART(yy,EMP_DATEOFJOINING)),2)UNION ALLselect left(DATEname(mm,ES_LAST_WORKING_DATE),3)+'-'+right(convert(varchar,DATEPART(yy,ES_LAST_WORKING_DATE)),2) "Month-Year", count(*) as "Number of exit Empl"from SEP_EMPLOYEE_SEPARATIONgroup by left(DATEname(mm,ES_LAST_WORKING_DATE),3)+'-'+right(convert(varchar,DATEPART(yy,ES_LAST_WORKING_DATE)),2))Ai want to sho output as month-yaer no.of joined emp no.of exit employebut i am getting mu output likeMonth-Year Number of joined Empl12-May 1612-May 19plesae suggest as its very importantregards,vipin jha |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-03 : 08:18:06
|
[code]; with emp_join as( select mth_yr = dateadd(month, datediff(month, 0, EMP_DATEOFJOINING), 0), cnt = count(*) from erm_employee_master group by dateadd(month, datediff(month, 0, EMP_DATEOFJOINING), 0)),emp_exit as( select mth_yr = dateadd(month, datediff(month, 0, ES_LAST_WORKING_DATE), 0), cnt = count(*) from SEP_EMPLOYEE_SEPARATION group by dateadd(month, datediff(month, 0, ES_LAST_WORKING_DATE), 0))select mth_yr = left(datename(month, coalesce(j.mth_yr, e.mth_yr)), 3) + '-' + right(datename(year, coalesce(j.mth_yr, e.mth_yr)), 2), j.cnt as [Number of joined Empl], e.cnt as [Number of exit Empl]from emp_join j full outer join emp_exit e on j.mth_yr = e.mth_yr[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
vipinjha123
Starting Member
45 Posts |
Posted - 2012-05-04 : 00:51:09
|
THANKX SIR I GOT THE SOLUTION THANX AGAINREGARDS,VIPIN JHA |
 |
|
vipinjha123
Starting Member
45 Posts |
Posted - 2012-05-04 : 02:30:32
|
Hello sir , if i want to add two colmun(location.department) in same querynow i want to see report as monthwise,locationwise,departmentwisefor example inmonth-year joinee exit location deptmay-12 12 5 mumbai ITMAY-12 10 2 MUMBAI ACCOUNTSwhat changes are required in above query developed by youwaiting for your prompt responseregards,Vipin jha |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-04 : 06:12:14
|
[code]; with emp_join as( select mth_yr = dateadd(month, datediff(month, 0, EMP_DATEOFJOINING), 0), location, department, cnt = count(*) from erm_employee_master group by dateadd(month, datediff(month, 0, EMP_DATEOFJOINING), 0), location, department),emp_exit as( select mth_yr = dateadd(month, datediff(month, 0, ES_LAST_WORKING_DATE), 0), location, department, cnt = count(*) from SEP_EMPLOYEE_SEPARATION group by dateadd(month, datediff(month, 0, ES_LAST_WORKING_DATE), 0), location, department)select mth_yr = left(datename(month, coalesce(j.mth_yr, e.mth_yr)), 3) + '-' + right(datename(year, coalesce(j.mth_yr, e.mth_yr)), 2), location, department, j.cnt as [Number of joined Empl], e.cnt as [Number of exit Empl]from emp_join j full outer join emp_exit e on j.mth_yr = e.mth_yr and j.location = e.location and j.department = e.department[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|