Temporary Tables performance issue

  • nadersam (10/7/2010)


    can u pls tell me whats wrong in this syntax, i am trying to use table valued functions instead

    Thanks

    Create function [GetTableData] (@TableName varchar(50),@RowID integer)

    returns table

    AS

    Declare @MySQL varchar(100);

    Set @Mysql= 'select * from ' + @TableName + ' where id = ' + @RowID

    exec (@Mysql)

    return

    As suggested in last post table valued function are not allowed in sql 2005

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • nadersam (10/7/2010)


    can u pls tell me whats wrong in this syntax, i am trying to use table valued functions instead

    Thanks

    Create function [GetTableData] (@TableName varchar(50),@RowID integer)

    returns table

    AS

    Declare @MySQL varchar(100);

    Set @Mysql= 'select * from ' + @TableName + ' where id = ' + @RowID

    exec (@Mysql)

    return

    The RETURNS clause is missing the definition of the output table. See here.

    Also, EXEC can only be used within a function to call an extended stored procedure.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thank you all guys, appreciate your help.

    Regards

    Nader

Viewing 3 posts - 31 through 32 (of 32 total)

You must be logged in to reply to this topic. Login to reply