如何编写存储过程来使用sql更新员工的出勤率 [英] how to write stored procedure to update attendance of an employee using sql

查看:83
本文介绍了如何编写存储过程来使用sql更新员工的出勤率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MS SQL SERVER2008R2

我想更新状态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



在CAST('08:00')之间选择CAST(@In_Punch AS TIME,@ Out_Punch AS TIME)时的情况时间)

和CAST('16:00'时间)那么'P'

什么时候(@Out_Punch AS TIME)在CAST('16:00'之间)时间)

和CAST('17:30'时间)然后'P'

- 什么时候(@In_Punch AS TIME)在CAST之间('08: 00'作为时间)

- 和CAST('09:30'时间)然后'P'

当CAST(@In_Punch AS TIME,@ Out_Punch AS TIME)之间('09:31'时间)

和CAST('15:59'时间)然后'HL'

ELSE'A'

--SELECT *来自MASTERPROCESSDAILYDATA,其中PDate> '02 -1-13'AND PDate< = '02 -28-13'



END

END

GO



任何人都可以帮我写SPC



我想输出如下< br $>




输出:



@PDate @In_Punch @Out_Punch状态



考虑任何月份08:00 AM至09:30 AM下午04:00至05:30 P

@In_Punch>上午9:30 @Out_Punch< = 03:59 PM HL

@In_Punch = NULL @ Out _Punch = NULL A

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

推荐答案

你似乎要求我们一步一步地完成所有工作。这是为什么 ?为什么你没有采纳我以前的建议来提高效率和可读性?



你的问题毫无意义。你给我们一个select语句(我们写的)并告诉我们你想要更新。你想基于什么更新?你有什么办法吗?



根据你的问题,我想你只想要



insert进入xxxx(其中xxxx是你的表名)







更新xxx设置yyy =(其中xxx是你的表名,yyy是你的专栏。



后跟你发布的SQL,它返回你想要插入的值。



当然,你需要插入你需要传递的其他值,但是现在你的问题太模糊了,无法提供更多信息。
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.


这篇关于如何编写存储过程来使用sql更新员工的出勤率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆