java create user_Create User count function

I got this view for the table below:

SELECT count(Incident.ID_Incident)

FROM Incident WHERE Incident.End_User = 7

AND Incident.Date BETWEEN '2018-12-01 07:54:44' AND '2018-12-18 00:00:00';

GO

Table:

CREATE TABLE Incident(

ID_Incident INT IDENTITY(1,1) NOT NULL,

Date DATETIME NULL,

End_User INT NOT NULL,

Here are some of the table values:

('2018-12-06 12:33:05', 003),

('2018-12-13 14:32:12', 010),

('2018-12-06 01:26:03', 015),

('2018-12-04 05:38:50', 012),

('2018-12-10 19:13:08', 011),

('2018-12-12 13:28:39', 005),

('2018-12-05 11:57:29', 006),

('2018-12-17 15:28:31', 007),

('2018-12-07 01:39:22', 007),

('2018-12-12 17:01:47', 009),

('2018-12-03 09:54:26', 010);

I need to turn that view into a Function. I dont know why it is not working.

Any advise would be great.

I wrote this:"

CREATE FUNCTION Total_case (@ID_End_User INT)

RETURNS INT AS

BEGIN

DECLARE @ID_End_User_Search INT

SELECT @ID_End_User_Search = COUNT(ID_Incident)

FROM Incident i

WHERE i.End_User = @ID_End_User_Search

AND i.Date BETWEEN '2018-12-13 14:32:12' AND '2018-12-18 00:00:00'

RETURN (@ID_End_User_Search)

END

GO

DECLARE @SearchValue INT;

EXEC @SearchValue = [dbo].Total_case

@ID_End_User = 7;

SELECT @SearchValue AS 'Total case per user.'

GO

Edit: Changed tags and added tables

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值