Click here to Skip to main content
12,304,203 members (70,494 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 29-Jan-13 1:44am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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


About DateDiff, use proper datepart you need. Here: MSDN: DATEDIFF (Transact-SQL)[^]
  Permalink  
v2
Comments
kshitij_CodeMaster 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Find ur modified code n use it

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 Smile | :)
  Permalink  
Comments
Member 9511889 29-Jan-13 8:11am
   
what is solution for datediff?
kshitij_CodeMaster 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
kshitij_CodeMaster 29-Jan-13 8:24am
   
wat value is getting saved in Duration field for ur db.?? check that duration field datatype should be Datetime
kshitij_CodeMaster 29-Jan-13 8:25am
   
please vote and click on ans accept as it worked for u.. :)
Member 9511889 29-Jan-13 8:29am
   
duration datatype is datetime
kshitij_CodeMaster 29-Jan-13 8:38am
   
run this in ur sql server sceen n see the output .. for me it comes as 0 min
SELECT DATEDIFF ( mi , '01/29/2013 2:06:00 AM' , '01/29/2013 2:06:10 AM' )
Member 9511889 30-Jan-13 0:49am
   
dateduration is not wprking.As posted you ,in my case i have use storeprocedure,so it is not working in my case.
kshitij_CodeMaster 30-Jan-13 0:55am
   
cn u provide ur entire SP here.. wll look n try to resolve error?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160530.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100