Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
if(@OutTime=null and @InTime!=null)
				begin
			UPDATE       Biometrics
			SET                [Name] =@Name, InTime =@InTime, Userid =@Userid, Group_Id=@Groupid where id=@id
				end
	
			else
			begin
			INSERT INTO Biometrics
	                        ([Name], InTime, Group_Id,Userid)
			VALUES        (@Name,@CheckTime,@Groupid,@Userid)
			end




	select top 1 @id=id from Biometrics where Userid=@Userid  order by id desc 
UPDATE       Biometrics
SET                [Name] = @Name, Group_Id = @Groupid, OutTime = @CheckTime, Duration=DateDiff(mi,@checktime,InTime)  where  id=@id





i have put if..else condition in my storeprocedure.but data in if is not fire.every time else condition is fire.i think i have mistack in
if(@OutTime=null and @InTime!=null)


second problem is datediff function. duration is comming but wrong difference is comming.what is solution for that.Everything is working fine except this two thing.So i have not any error in my code.
Posted

Use: MSDN: ISNULL (Transact-SQL)[^] & MSDN: IS [NOT] NULL (Transact-SQL)[^] as per need for comparison.

Example:
SQL
IF ((@OutTime IS NULL) AND (@InTime IS NOT NULL))



About DateDiff, use proper datepart you need. Here: MSDN: DATEDIFF (Transact-SQL)[^]
 
Share this answer
 
v2
Comments
[no name] 29-Jan-13 8:04am    
u need date difference in days or hrs or mins...?? cn u explain ur requirement a bit more wid example of output as needed by u.
Member 9511889 29-Jan-13 8:11am    
i want output in minute.for that i have use Datediff(mi,outtime,intime).but it is not working.
Sandeep Mewara 29-Jan-13 8:12am    
Elaborate 'not working'.
Member 9511889 29-Jan-13 8:18am    
intime:01/29/2013 2:06:00 AM outtime:01/29/2013 2:06:10 AM
then duration: 01/01/1900 12:00:00 AM
Find ur modified code n use it

SQL
if(@OutTime is null and @InTime is not null)
                begin
            UPDATE       Biometrics
            SET                [Name] =@Name, InTime =@InTime, Userid =@Userid, Group_Id=@Groupid where id=@id
                end

            else
            begin
            INSERT INTO Biometrics
                            ([Name], InTime, Group_Id,Userid)
            VALUES        (@Name,@CheckTime,@Groupid,@Userid)
            end




    select top 1 @id=id from Biometrics where Userid=@Userid  order by id desc
UPDATE       Biometrics
SET                [Name] = @Name, Group_Id = @Groupid, OutTime = @CheckTime, Duration=DateDiff(mi,@checktime,InTime)  where  id=@id




Hope it solves ur problems.
Dnt forget to click accpt ans and vote for it if it works for u.
Enjoy :)
 
Share this answer
 
Comments
Member 9511889 29-Jan-13 8:11am    
what is solution for datediff?
[no name] 29-Jan-13 8:16am    
put Duration = DATEDIFF ( mi , InTime , @checkTime)
Member 9511889 29-Jan-13 8:23am    
if..else is working...thanks for that.. datediff is not working
[no name] 29-Jan-13 8:24am    
wat value is getting saved in Duration field for ur db.?? check that duration field datatype should be Datetime
[no name] 29-Jan-13 8:25am    
please vote and click on ans accept as it worked for u.. :)

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