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  | 
                             
                            
                                    | 
                                         indr4w 
                                        Starting Member 
                                         
                                        
                                        27 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2013-05-28 : 04:34:52
                                            
  | 
                                             
                                            
                                            | Hallo How to show in 1 row on the grid for Work In and Work Out Over 24Hour in sqlExample :USERID NAME    CHECKIN              CHECKOUT007    TOM     28/05/2013 19:00:00  29/05/2013 07:00:00 | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-05-28 : 05:06:42
                                          
  | 
                                         
                                        
                                          | you need to have two fields in your table of type datetime for storing CHECKIN and CHECKOUT and then a simple insert would be enough.For displaying just do SELECT * FROM table.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-10 : 03:24:37
                                          
  | 
                                         
                                        
                                          | I mean like this Mr. VisakhExample:I have Table checkinoutuserid name       checktime007    raju       28/05/2013 19:00:00  ---> in007    raju       29/05/2013 07:00:00  ---> outand I want to display the grid to be "USERID NAME CHECKIN             CHECKOUT007    raju 28/05/2013 19:00:00 29/05/2013 07:00:00thanks  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     bandi 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    2242 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-10 : 03:38:03
                                          
  | 
                                         
                                        
                                          quote: Originally posted by indr4w I mean like this Mr. VisakhExample:I have Table checkinoutuserid name       checktime007    raju       28/05/2013 19:00:00  ---> in007    raju       29/05/2013 07:00:00  ---> outand I want to display the grid to be "USERID NAME CHECKIN             CHECKOUT007    raju 28/05/2013 19:00:00 29/05/2013 07:00:00thanks
  How to find the IN, OUT date values.... Is there any specific time ranges to represent IN/OUT?If you have only two rows per userid, then you can use as follows:SELECT userid, name, MIN(checktime) CheckIn, MAX(checktime) CheckOutFROM YourTableGROUP BY userid, name--Chandu  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-10 : 04:51:38
                                          
  | 
                                         
                                        
                                          | Hi see the date (I have different date)  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-10 : 08:12:41
                                          
  | 
                                         
                                        
                                          Assuming there's a type field to indicate IN,OUTSELECT userid,name,checktime,MinTimeFROM TableOUTER APPLY (SELECT MIN(checktime) AS MinTime             FROM Table             WHERE userid = t.userid             AND name = t.name             AND checktime > t.checktime             AND type = 'OUT'           )t1WHERE t.type='IN' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 03:08:56
                                          
  | 
                                         
                                        
                                          | Hallo Mr. VisakhThere are a few tables :GOCREATE TABLE [dbo].[CHECKINOUT] (	[USERID] [int] NOT NULL ,	[CHECKTIME] [datetime] NOT NULL ,	[CHECKTYPE] [nvarchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOINSERT INTO CHECKINOUT VALUES(256, '29/04/2013 19:03:30', 'I'),(256, '30/04/2013 06:34:42', 'O'),(205, '03/04/2013 21:56:13', 'I'),(205, '04/04/2013 06:01:15', 'O');GOCREATE TABLE [dbo].[USERINFO] (	[USERID] [int] IDENTITY (1, 1) NOT NULL ,	[Badgenumber] [nvarchar] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,	[Name] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]GOINSERT INTO USERINFO VALUES(256, '1061052', 'TAJUDIN'),(205, '1061010', 'RAJU');GOCREATE TABLE [dbo].[SchClass] (	[schClassid] [int] IDENTITY (1, 1) NOT NULL ,	[schName] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,	[StartTime] [datetime] NOT NULL ,	[EndTime] [datetime] NOT NULL) ON [PRIMARY]GOINSERT INTO SchClass VALUES (4, 'NIGHT SHIFT', '23:00:00', '07:00:00'),(6, 'LONG  SHIFT', '19:00:00', '07:00:00');GOCREATE TABLE [dbo].[UserUsedSClasses] (	[UserId] [int] NOT NULL,	[SchId] [int] NOT NULL ) ON [PRIMARY]GOINSERT INTO UserUsedSClasses VALUES(256, 6),(205, 4);I want the output like this :USERID NAME    SCHNAME     DATEIN     TIMEIN     DATEOUT    TIMEOUT256    TAJUDIN LONG SHIFT  29/04/2013 19:03:30   30/04/2013 06:34:42205    RAJU    NIGHT SHIFT 03/04/2013 21:56:13   04/04/2013 06:01:15Thanks  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 03:41:07
                                          
  | 
                                         
                                        
                                          | [code]SELECT ui.[USERID],ui.[Name],sc.schName,CONVERT(varchar(10),cin.CHECKTIME,103) AS DATEIN,CONVERT(varchar(8),cin.CHECKTIME,108) AS TIMEIN ,CONVERT(varchar(10),cout.CHECKTIME,103) AS DATEOUT,CONVERT(varchar(8),cout.CHECKTIME,108) AS TIMEOUTFROM USERINFO uiINNER JOIN SchClass scON sc.UserId = ui.USERIDINNER JOIN CHECKINOUT cinON cin.USERID = ui.USERIDAND cin.CHECKTYPE = 'I'INNER JOIN CHECKINOUT coutON cout.USERID = ui.USERIDAND cout.CHECKTYPE = 'O'AND cout.CHECKTIME BETWEEN cin.CHECKTIME AND DATEADD(dd,DATEDIFF(dd,0,cin.CHECKTIME),sc.EndTime)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 04:24:49
                                          
  | 
                                         
                                        
                                          | Sorry,how about table UserUsedSClasses  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 04:34:57
                                          
  | 
                                         
                                        
                                          ah...missed thatSELECT ui.[USERID],ui.[Name],sc.schName,CONVERT(varchar(10),cin.CHECKTIME,103) AS DATEIN,CONVERT(varchar(8),cin.CHECKTIME,108) AS TIMEIN ,CONVERT(varchar(10),cout.CHECKTIME,103) AS DATEOUT,CONVERT(varchar(8),cout.CHECKTIME,108) AS TIMEOUTFROM USERINFO uiINNER JOIN UserUsedSClasses uusON uus.UserId = ui.USERIDINNER JOIN SchClass scON sc.schClassid = uus.SchIdINNER JOIN CHECKINOUT cinON cin.USERID = ui.USERIDAND cin.CHECKTYPE = 'I'INNER JOIN CHECKINOUT coutON cout.USERID = ui.USERIDAND cout.CHECKTYPE = 'O'AND cout.CHECKTIME BETWEEN cin.CHECKTIME AND DATEADD(dd,DATEDIFF(dd,0,cin.CHECKTIME),sc.EndTime) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 05:30:10
                                          
  | 
                                         
                                        
                                          | Sorry, nothing haven  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 05:30:50
                                          
  | 
                                         
                                        
                                          | what does that mean?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 05:34:15
                                          
  | 
                                         
                                        
                                          | Execute is ok but file cannot display.Please to check the table step by stepSorry Mr. Visaks i am newbie  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 06:17:18
                                          
  | 
                                         
                                        
                                          it should be this i guessSELECT ui.[USERID],ui.[Name],sc.schName,CONVERT(varchar(10),cin.CHECKTIME,103) AS DATEIN,CONVERT(varchar(8),cin.CHECKTIME,108) AS TIMEIN ,CONVERT(varchar(10),cout.CHECKTIME,103) AS DATEOUT,CONVERT(varchar(8),cout.CHECKTIME,108) AS TIMEOUTFROM USERINFO uiINNER JOIN UserUsedSClasses uusON uus.UserId = ui.USERIDINNER JOIN SchClass scON sc.schClassid = uus.SchIdINNER JOIN CHECKINOUT cinON cin.USERID = ui.USERIDAND cin.CHECKTYPE = 'I'INNER JOIN CHECKINOUT coutON cout.USERID = ui.USERIDAND cout.CHECKTYPE = 'O'AND cout.CHECKTIME BETWEEN cin.CHECKTIME AND DATEADD(dd,DATEDIFF(dd,0,cout.CHECKTIME),sc.StartTime) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 06:38:14
                                          
  | 
                                         
                                        
                                          | So I changed to be like this :AND cout.CHECKTIME BETWEEN cin.CHECKTIME AND DATEADD(dd,DATEDIFF(dd,sc.StartTime,cin.CHECKTIME),0)the Results is :256	TAJUDIN	LONG SHIFT	29/04/2013	19:03:30	30/04/2013	06:34:42205	RAJU	NIGHT SHIFT	03/04/2013	21:56:13	04/04/2013	06:01:15as expected  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-13 : 06:54:36
                                          
  | 
                                         
                                        
                                          | Nope it should be the way i gave as out time can be anywhere until next day shift start------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     indr4w 
                                    Starting Member 
                                     
                                    
                                    27 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-28 : 03:09:53
                                          
  | 
                                         
                                        
                                          | Hi Mr. Visakhsorry to disturb againI want to ask again, what if from the above table, I want to display the results like this:USERID NAME    SCHNAME     CHECKTIME AS CHECKIN  CHECKTIME AS CHECKOUT156    INDRA   NON SHIFT   29/04/2013 07:00:30   30/04/2013 18:30:02256    TAJUDIN LONG SHIFT  29/04/2013 19:03:30   30/04/2013 06:34:42205    RAJU    NIGHT SHIFT 03/04/2013 21:56:13   04/04/2013 06:01:15date and time are not in separate.Thanks  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-06-28 : 03:39:55
                                          
  | 
                                         
                                        
                                          do you mean you want them in same field in output?SELECT ui.[USERID],ui.[Name],sc.schName,cin.CHECKTIME AS DATEIN,cout.CHECKTIME AS DATEOUTFROM USERINFO uiINNER JOIN UserUsedSClasses uusON uus.UserId = ui.USERIDINNER JOIN SchClass scON sc.schClassid = uus.SchIdINNER JOIN CHECKINOUT cinON cin.USERID = ui.USERIDAND cin.CHECKTYPE = 'I'INNER JOIN CHECKINOUT coutON cout.USERID = ui.USERIDAND cout.CHECKTYPE = 'O'AND cout.CHECKTIME BETWEEN cin.CHECKTIME AND DATEADD(dd,DATEDIFF(dd,0,cout.CHECKTIME),sc.StartTime) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |   
     
     
            
              
	     |  
		
			
     
          
		 |