gpt4 book ai didi

sql - T-SQL RETURN 不起作用

转载 作者:行者123 更新时间:2023-12-04 22:34:00 24 4
gpt4 key购买 nike

我的 T-SQL 有问题,无法查看表中是否存在该项目,但出现错误消息

Msg 178, Level 15, State 1, Line 2 A RETURN statement with a return value cannot be used in this context. Msg 178, Level 15, State 1, Line 4 A RETURN statement with a return value cannot be used in this context.


IF EXISTS(SELECT COUNT(timesheetID)
FROM [TaskManagementSystem_DB].[dbo].[Timesheet_entry]
WHERE userID ='12' AND CONVERT(date, startTimeStamp)=CONVERT(date, getdate()))
RETURN 1
else
RETURN 0

整个代码:
ALTER PROCEDURE [dbo].[CheckTimesheetIsEXISTS_forUser]  @UserID uniqueidentifier

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements. SET NOCOUNT ON;

IF EXISTS(SELECT COUNT(timesheetID) FROM
[TaskManagementSystem_DB].[dbo].[Timesheet_entry]
WHERE userID
='3fd971f7-e6e8-40fe-a90d-a7c9df8bf7b5'
AND CONVERT(date, startTimeStamp)=CONVERT(date, getdate()))



RETURN 1
else
RETURN 0
END

最佳答案

试试这个:

ALTER PROCEDURE [dbo].[CheckTimesheetIsEXISTS_forUser]  @UserID uniqueidentifier

AS
BEGIN

SELECT CASE WHEN COUNT(timesheetID) > 0 THEN 1 ELSE 0 END AS isExists
FROM [TaskManagementSystem_DB].[dbo].[Timesheet_entry]
WHERE userID = @UserID AND CONVERT(date, startTimeStamp)=
CONVERT(date, getdate())

END

关于sql - T-SQL RETURN 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com