T-SQL RETURN is not working

I have Problem with My T-SQL to see if the item EXISTS on the table but I have the error message

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

The whole code:

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

Answers


Try this:

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

Return works inside a stored procedure/user defined functions.

Simple tsql is just batch of commands. I guess you want to write SELECT instead of RETURN.


You can only call return in stored procedures and functions. I'm assuming this isn't either.


Need Your Help

IntelliJ productivity tips running tomcat

java spring tomcat intellij-idea jetty

I'm developing using IntelliJ 11u on a spring mvc application using tomcat.

Need help with RX:Convert System.Diagnostics.Process.OutputDataReceived to an Observable

c# events system.reactive

I want to start a subprocess and watch it's redirected output. That not

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.