-
Problems using IF..else Statments in UDF
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
-
--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)
-
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)
-
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!
Last edited by Studious01; 12-18-2003 at 03:27 PM.
-
Please post sample data and expected results. You dont really need a cursor. Cursor is expensive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|