Calling & writing a user defined function RRS feed

  • Question

  • Hi all,

    I have a written my own function in SQL. It will return a number of unique identifiers, it could be up to thousands. I will then check if a certain ID is in the data that's returned. So, should this data be returned in a table??

    Here's the function code, I'm unsure about the 'returns' statement. I just copied that part from somewhere else.

    CREATE function [dbo].[fn_GetPersonIDs] ( @personType int ) returns @tbl table ( id uniqueidentifier primary key clustered ) as begin Select contactid from Contact C

    where type = @personType


    I'm not really sure how I'd call it as I'm unsure what the return type will be, but it would be something like this (I know this is only really pseudocode):

    DECLARE @return = fn_GetPersonIDs(@thisPersonType)
    select ID from Person
    where ID NOT IN
    (select contactid from @return)


    Wednesday, January 16, 2013 9:31 AM