Home » Databases » Sybase » ASE » unable to create a SQL UDF in Sybase ASE using a case statement

unable to create a SQL UDF in Sybase ASE using a case statement

create function ok (@boolean bit)
returns varchar(2000) as
declare @output_string varchar(2000)
select @output_string = case when @boolean = 1 then "" else "not " end
set @output_string = @output_string + "ok"
return @output_string
end

Msg 156, Level 15, State 2
Server ‘DBADEV1’, Procedure ‘ok’, Line 7
Incorrect syntax near the keyword ‘end’.
I’m trying to write an ASE implementation of TAP. A rudimentary TAP implementation for PostgreSQL is at http://www.justatheory.com/computers/databases/postgresql/introducing_pgtap.html
I’ve been able to use case in SQL UDFs before – see http://froebe.net/blog/2007/10/10/porting-mysqls-date_format-function-to-sybase-ase-1502/
Adaptive Server Enterprise/15.0.2/EBF 15654 ESD#4/P/Linux Intel/Linux 2.4.21-47.ELsmp i686/ase1502/2528/32-bit/FBO/Sat Apr 5 05:18:42 2008
I’m just missing something blindingly simple… I just know it.

Share Button

Comments

  1. Dan says:

    Hey Jason, you forgot the begin statement for your end statement 🙂

    create function ok (@boolean bit)
    returns varchar(2000) as
    begin —- need begin here!
    declare @output_string varchar(2000)
    select @output_string = case when @boolean = 1 then “” else “not ” end
    set @output_string = @output_string + “ok”
    return @output_string
    end

  2. doh! I knew I forgot something simple! thanks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Facebook login by WP-FB-AutoConnect