Home Forums SQL Server 2005 T-SQL (SS2K5) MSG 444 - Select statements included within a function cannot return data to a client. RE: MSG 444 - Select statements included within a function cannot return data to a client.

  • Scalar functions are usually a performance problem because they execute row by row. The best option for performance when you need parameters is an inline table valued function which is written like thisÑ

    CREATE FUNCTION hstore_num ()

    RETURNS TABLE

    AS

    RETURN

    SELECT TOP 1 'Highest Store Count' = COUNT(state)

    FROM stores

    GROUP BY state

    ORDER BY 'Highest Store Count' DESC;

    GO

    Of course, with no parameters, you could use a view instead

    CREATE VIEW hstore_num

    AS

    SELECT TOP 1 'Highest Store Count' = COUNT(state)

    FROM stores

    GROUP BY state

    ORDER BY 'Highest Store Count' DESC;

    GO

    Both of them would be called as a table, but the function needs to use parenthesis.

    SELECT *

    FROM hstore_num() --

    Hope this is clear.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2