Results 1 to 5 of 5

Thread: Problems using IF..else Statments in UDF

  1. #1
    Join Date
    Dec 2003
    Posts
    7

    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

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    --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)

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    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)

  4. #4
    Join Date
    Dec 2003
    Posts
    7
    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.

  5. #5
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    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
  •