Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am using MS SQL SERVER2008R2
I want to update status AS 'P','A','HL'

SPC:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE SP_DIFF(@FromDate datetime,@ToDate datetime)
AS
BEGIN
SET NOCOUNT ON;

DECLARE
@In_Punch datetime,
@Out_Punch datetime
--@PDate datetime

SELECT CASE WHEN CAST(@In_Punch AS TIME,@Out_Punch AS TIME ) BETWEEN CAST ('08:00' AS TIME)
AND CAST('16:00' AS TIME) THEN 'P'
WHEN CAST(@Out_Punch AS TIME ) BETWEEN CAST ('16:00' AS TIME)
AND CAST('17:30' AS TIME) THEN 'P'
--WHEN CAST(@In_Punch AS TIME ) BETWEEN CAST ('08:00' AS TIME)
--AND CAST('09:30' AS TIME) THEN 'P'
WHEN CAST(@In_Punch AS TIME,@Out_Punch AS TIME ) BETWEEN CAST ('09:31' AS TIME)
AND CAST('15:59' AS TIME) THEN 'HL'
ELSE 'A'
--SELECT *FROM MASTERPROCESSDAILYDATA where PDate > '02-1-13' AND PDate <= '02-28-13'

END
END
GO

Can anyone help me how to write SPC

I want output as follows


OUTPUT:

@PDate @In_Punch @Out_Punch Status

Consider for any month Between 08:00 AM to 09:30AM Between 04:00 PM to 05:30 PM P
@In_Punch > 09:30 AM @Out_Punch <=03:59 PM HL
@In_Punch = NULL @ Out _Punch = NULL A
Posted
Updated 30-Dec-13 18:15pm
v2

1 solution

You seem to be asking us to do all your work, one step at a time. Why is that ? Why have you not taken my previous advice on making this more efficient and readable ?

Your question makes no sense. You give us a select statement ( which we wrote ) and tell us you want to update. What do you want to update based on ? What have you done about it ?

Based on your question, I think you just want

insert into xxxx ( where xxxx is your table name )

or

update xxx set yyy = ( where xxx is your table name and yyy is your column )

followed by the SQL you posted, which returns the values you want to insert.

Of course you'd need to insert the other values you need to pass through, but your question is just too vague to give more information, right now.
 
Share this answer
 
Comments
Karthik Achari 31-Dec-13 0:41am    
I tried with that also but it is not working
Insted of changing Status each and every time by specifying particular Emp_id I am trying to update Dynamically
Christian Graus 31-Dec-13 0:53am    
Well, that's how it's done. So post what you tried, so we can try to fix it. SQL questions are different - without your tables it's hard to give an answer, and anything you can show us, helps.
Christian Graus 31-Dec-13 0:54am    
Oh, you are also still posting the SQL that flat out cannot work, unless it works in SS 2012. In 2008R2, CAST(@In_Punch AS TIME,@Out_Punch AS TIME ) gives an error.

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