SQL Stored Procedure and Function

Anything can be programmable with defined syntax and common lib.

 1 ALTER PROCEDURE [dbo].[sp_GetLaborHourPerDayEmployee](@au_Date DATETIME, @au_employeeID VARCHAR(30))
 2     -- Add the parameters for the stored procedure here
 3 AS
 4 BEGIN
 5     -- SET NOCOUNT ON added to prevent extra result sets from
 6     -- interfering with SELECT statements.
 7     SET NOCOUNT ON;
 8     DECLARE @au_ItemDate DATETIME;
 9 
10     SET @au_ItemDate = CONVERT(VARCHAR(10), @au_Date, 120);
11     
12     SELECT SUM(ISNULL(T1.Hours,0)) as Hours
13     FROM [dbo].[LBS_Maintenance] as T0
14     left join [dbo].[LBS_LaborHour] as T1
15     on T0.MaintenanceID = T1.MaintenanceID     
16     where T0.IsFlag = 0 
17     and CONVERT(VARCHAR(10),T0.ItemDate,120) = @au_ItemDate
18     and T0.EmployeeID = @au_employeeID
19     --and (T2.CurrentStatus = 'Active' or (T2.CurrentStatus = 'Suspend' and T2.SuspendWhat = 'Billing'))            
20 END

 

 

 

 1 USE [OES_LBS]
 2 GO
 3 /****** Object:  UserDefinedFunction [dbo].[fn_GetLaborHourPerDayEmployee]    Script Date: 08/07/2013 16:17:00 ******/
 4 SET ANSI_NULLS ON
 5 GO
 6 SET QUOTED_IDENTIFIER ON
 7 GO
 8 -- =============================================
 9 -- Author:        <Author,,Name>
10 -- Create date: <Create Date,,>
11 -- Description:    <Description,,>
12 -- =============================================
13 ALTER FUNCTION [dbo].[fn_GetLaborHourPerDayEmployee](@au_Date DATETIME, @au_employeeID VARCHAR(30))
14 RETURNS NUMERIC(5,2)  
15 AS
16 BEGIN
17     DECLARE @ret NUMERIC(5,2)
18     SET @ret = 0
19     SELECT @ret = A0.Hours
20     FROM
21     (
22         SELECT SUM(ISNULL(T1.Hours,0)) as Hours
23         FROM [dbo].[LBS_Maintenance] as T0
24         left join [dbo].[LBS_LaborHour] as T1
25         on T0.MaintenanceID = T1.MaintenanceID     
26         where IsFlag = 0 
27         and T0.ItemDate = @au_Date
28         and T0.EmployeeID = @au_employeeID
29         --and (T2.CurrentStatus = 'Active' or (T2.CurrentStatus = 'Suspend' and T2.SuspendWhat = 'Billing'))        
30         --and T1.Hours != 0
31     )as A0
32 RETURN(@ret)
33 END

 

 

 

转载于:https://www.cnblogs.com/iiiDragon/p/3243386.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值