Results 1 to 3 of 3

Thread: User Functions as params to Stored Procs

  1. #1
    Join Date
    Mar 2003
    Location
    UK
    Posts
    2

    User Functions as params to Stored Procs

    Can I use the result of a scalar function as the parameter for a stored procedure? ie

    exec [dbo].[usp_insert_into_table]
    @integer = [dbo].[uf_getAnIDfromName]('PLAYER')

    where the @integer parameter expects an integer and the user function uf_getAnIDFromName returns an integer related to the 'PLAYER' name.

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    I dont think so. u need a variable.


    create proc test @var1 int as
    print @var1

    create function udf1 (@x varchar(10))
    returns int
    as
    begin
    declare @y int
    if @x = 'Player'
    begin
    set @y =1
    end
    else
    begin
    set @y =5
    end

    return @y
    end

    --select dbo.udf1('Playerw')

    declare @xx int
    set @xx = dbo.udf1('Playerw')
    exec test @var1 = @xx

  3. #3
    Join Date
    Mar 2003
    Location
    UK
    Posts
    2
    Thanks MAK.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •