sortcolumn And SortOrder

  • Stored Procedure -How to Pass @SortColumn And @SortOrder

  • vinaseetha87 (6/20/2011)


    Stored Procedure -How to Pass @SortColumn And @SortOrder

    I did not understand your question correctly. Stilly try to reply with.

    Syntax:

    EXEC dbo.spStoredProcedureName @SortCOlumn = 'ColumnName', @SortOrder = 'SortOrder'

    For example:

    EXEC dbo.spAddressList @SortCOlumn = 'City', @SortOrder = 'ASC'

  • vinaseetha87 (6/20/2011)


    Stored Procedure -How to Pass @SortColumn And @SortOrder

    SQL is a declarative language, i.e. this does not work:

    DECLARE @SortOrder NCHAR(4),

    @SortColumn SYSNAME ;

    SET @SortOrder = 'ASC' ;

    SET @SortColumn = N'name' ;

    SELECT *

    FROM master.sys.tables

    ORDER BY @SortColumn @SortOrder ;

    Why are you trying to offer this functionality from SQL? Changing the order of results is better left to the presentation layer.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 3 posts - 1 through 2 (of 2 total)

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