Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
EXAMPLE:EMPID EMPNAME G F S T DT
1 DURGA 0 0 0 0 2016-02-01
2 DURGA 0 0 0 0 2016-02-02

I NEED BELOW EXMAPLE PLAESE HELP ME HOW TO CONVERT THIS
2016-02-01 2016-02-02
EMPID EMPNAME G F S T G1 F2 S2 T2

What I have tried:

SQL
USE [INVATTENDENCE]
GO
/****** Object:  UserDefinedFunction [dbo].[FN_GETATT]    Script Date: 02/08/2016 21:52:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

--SELECT * FROM [dbo].[FN_GETATT](20,'Operations - AHP','2016-02-05')


ALTER FUNCTION [dbo].[FN_GETATT]
(
@siteid int,
@dept_name varchar(50),
@todate datetime
   )
RETURNS  TABLE
as

return(
select * from(
select * from(
      SELECT  et.emp_id,emp.emp_name,ROW_NUMBER() OVER(PARTITION BY emp.emp_code ORDER BY emp.EFFECTIVE_FROM DESC) AS Row,
                isnull(et.GENERAL_SHIFT,0) as g, 
                isnull(et.FIRST_SHIFT,0) as f, 
                isnull(et.SECOND_SHIFT,0) as s, 
                isnull(et.THIRD_SHIFT,0) as t,
                isnull(convert(DATETIME,'20'+convert(varchar(10),et.year,120)+'-'+ 
         convert(varchar(10),et.month,120)+'-'+
         convert(varchar(10),et.day,120)),0) as dt

              from  EMP_FPONM_EMP_TIME_SHEET et JOIN 
        EMP_FPONM_EMPLOYEE_INFORMATION emp on et.EMP_ID = emp.EMP_CODE
        where  
 emp.dept_name = @dept_name
    and emp.STATUS='Present'  
    and emp.SITE_ID=@siteid 
   and Convert(nvarchar(50),DATEPART(YYYY,@todate))+'-'+ Convert(nvarchar(50),DATEPART(MM,@todate))>=Convert(nvarchar(50),DATEPART(YYYY,(emp.EFFECTIVE_FROM)))+'-'+ Convert(nvarchar(50),DATEPART(MM,(emp.EFFECTIVE_FROM)))

  ) as a where  dt between DATEADD(day, -6, @todate) and DATEADD(day, -1, @todate)) as b where b.Row=1

  )
Posted
Comments
durga63 9-Feb-16 3:55am    
Hi any one please suggeset for above question kindly do the needfull
durga63 9-Feb-16 4:02am    
iam waiting for your reply i didn't get any idea
CHill60 16-Mar-16 10:01am    
Your expected results are not clear.
As an aside you should not be doing all those Converts on the dates in your query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900