# Related Sites > SQL Course >  Problems using IF..else Statments in UDF

## Studious01

Hi all,

I am trying to use the conditinal If..Else statements in creating UDF,
but i keep receiving an error message that states:

Incorrect syntax near the keyword 'Else'

Any suggestions in helping me to resolve this problem would be greatly
appreciated.

Smitty

----------


## MAK

--Example

create function dbo.Getoddeven (@number int)
returns varchar(4)
as
begin
declare @oddeven varchar(4)
set @oddeven = case when Convert(decimal(10,2),@number)/2- @number/2 = 0 then 'Even' 
else 'Odd' end
return @oddeven
end



--select dbo.Getoddeven (4)
--select dbo.Getoddeven (5)

----------


## MAK

create function dbo.Getoddeven (@number int)
returns varchar(4)
as
begin
declare @oddeven varchar(4)
if Convert(decimal(10,2),@number)/2- @number/2 = 0 
begin
set @oddeven ='Even' 
end else
begin
set @oddeven ='Odd' 
end
return @oddeven
end



--select dbo.Getoddeven (4)
--select dbo.Getoddeven (5)

----------


## Studious01

Thanks for all your help!

I was wandering if you can help me with something else...

I am trying to determine the sales revenue for an employee using three
table,employee, orders, and details ororder,using a stored procedure and a cursor.

is there as way to connect back to the employee the sales revenue calculated after using a aggregate function from
table detailsoforder,such as...

@sales revenue=quantity*price
for this employee...
Thanks!

----------


## MAK

Please post sample data and expected results. You dont really need a cursor. Cursor is expensive.

----------

