locked
Passing a suquery to a function as a parameter RRS feed

  • Question

  •  

    How would one pass a subquery to a function as a parameter?

     

    I have a function, f_Split that returns a table and has two parameters @List varchar(max) and @Delim char(1).  I'd like to use it to normalize rows in a table and return the results for use in a report. I tried the following:

     

    SELECT * FROM dbo.f_Split((SELECT Code FROM Codes WHERE ID = 10), '|')

     

    I'm getting a syntax error for the subquery.  Could anyone show me the proper way to pass a subquery to a function, even if the function is different from what I have defined here.

     

    Thanks,

    DD

    Thursday, February 28, 2008 6:02 PM

Answers

  • You can’t pass the subquery result as function param..

    If you use SQL Server 2005, then you can manage to get your desired output using the cross apply..

    SELECT * FROM Codes

                    Cross Apply dbo.f_Split(Code, '|')

    WHERE

                    ID = 10

    Thursday, February 28, 2008 6:18 PM

All replies

  • You can’t pass the subquery result as function param..

    If you use SQL Server 2005, then you can manage to get your desired output using the cross apply..

    SELECT * FROM Codes

                    Cross Apply dbo.f_Split(Code, '|')

    WHERE

                    ID = 10

    Thursday, February 28, 2008 6:18 PM
  •  

    You rock!  Thanks man!
    Thursday, February 28, 2008 6:34 PM