Assigning parameters in a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    Assigning parameters in a function

    I am trying to create a function in SQL 2000. Im rusty on function
    syntax and need to also assign some variables for use within this
    function.

    Example:
    create function blah (@param1 int)

    declare @var1 int, @var2 int

    --it doesnt like this method of assigning values to my
    variables?????? ????
    select @var1, @var2 = (select name, phone from customer where id =
    @param1)

    --Then I need to use those variables in this next statement...

    DECLARE @Zip int
    SELECT @Results = (select zip from table2 where name = @var1 and phone
    = @var2)

    return @Results

    -----------------------------------
    Any help would be greatly appreciated at filling in the missing
    syntax.
  • Dan Guzman

    #2
    Re: Assigning parameters in a function

    > --it doesnt like this method of assigning values to my[color=blue]
    > variables?????? ????
    > select @var1, @var2 = (select name, phone from customer where id =
    > @param1)[/color]

    Try:

    select @var1= name, @var2 = phone
    from customer where id = @param1

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    "Dave" <funkdm1@yahoo. com> wrote in message
    news:f5174e0f.0 404291539.211a5 032@posting.goo gle.com...[color=blue]
    > I am trying to create a function in SQL 2000. Im rusty on function
    > syntax and need to also assign some variables for use within this
    > function.
    >
    > Example:
    > create function blah (@param1 int)
    >
    > declare @var1 int, @var2 int
    >
    > --it doesnt like this method of assigning values to my
    > variables?????? ????
    > select @var1, @var2 = (select name, phone from customer where id =
    > @param1)
    >
    > --Then I need to use those variables in this next statement...
    >
    > DECLARE @Zip int
    > SELECT @Results = (select zip from table2 where name = @var1 and phone
    > = @var2)
    >
    > return @Results
    >
    > -----------------------------------
    > Any help would be greatly appreciated at filling in the missing
    > syntax.[/color]


    Comment

    Working...