laura
laura

Reputation: 2135

How to create a function in SQL Server that returns bit

I want to create a function that verifies if the current version of an application is the last version which exists in the database. This function has to retrieve 0 or 1. This is what i tried so far but it's giving Msg 102, Incorrect syntax near 'return'. How to make this work?

create function isLastVersion(
     @currentVersion nvarchar(10),
     @appCode nvarchar(128),
     @serial nvarchar(128))
returns bit
as 
begin
    declare @ret bit
    select @ret = case 
when @currentVersion = (select *from getAppLastVersion(@appCode,@serial)) 
then 1 else 0
    return @ret
end

Upvotes: 0

Views: 856

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180947

You're missing end on your case;

select @ret = case when @currentVersion = (select *from getAppLastVersion(@appCode,@serial)) 
              then 1 else 0 END

Upvotes: 4

Related Questions