Results 1 to 4 of 4

Thread: How to stored procedure and large table are dynamic order by performance

  1. #1
    Join Date
    Dec 2008
    Posts
    112

    How to stored procedure and large table are dynamic order by performance

    I have a project work where there was a requirement that, there's a way using MSSQL to dynamically determine what column should be ordered by in a select, This is because the main motive behind creating this is to look into sorting tables by a column designated given some input, and when i search for that on the internet I found that there is no easy way to do this. Does anyone provide me simple way to achieve this.

    Thanks

  2. #2
    Join Date
    Dec 2008
    Posts
    161

    Re: How to stored procedure and large table are dynamic order by performance

    I think you need to choose the parameter to specify the sort type and also make use of case statement in the order by clause. Here i will provide you the simple coding about how do you need to implement it,

    AS
    BEGIN

    SELECT
    TableField.colmnA,
    TableField.colmnB
    FROM
    TableField
    ORDER BY
    CASE
    WHEN @SortType = 1 THEN FieldA
    WHEN @SortType = 2 THEN FieldB
    ELSE FieldA
    END

    END

  3. #3
    Join Date
    Dec 2008
    Posts
    112

    Re: How to stored procedure and large table are dynamic order by performance

    Your idea of paging the data is a very good one. The part that is bad is using variables for the table names, order by, etc. but I need to be able to change the asc/desc too. I guess that'd reduce it to 2 queries though, which is something, but it'd be a real mess with the number of fields it's on.

  4. #4
    Join Date
    Jan 2009
    Posts
    140

    Re: How to stored procedure and large table are dynamic order by performance

    I think you need to use the INSERT INTO and ORDER BY methods to be used in your program to sort the items, and If sorting column is defferent from the PK, then SortColumn must be fetched as well, otherwise just the PK is necessary, and once this has been done then use the Join method to be used. This will combine all the data and sort the table content.

Similar Threads

  1. Stored procedure in MySQL database
    By Ameeryan in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 10:31 PM
  2. Use Of Stored Procedure in SQL Server
    By technika in forum Software Development
    Replies: 5
    Last Post: 30-01-2010, 11:24 AM
  3. What is sqlca Informix stored Procedure
    By Bosch in forum Software Development
    Replies: 3
    Last Post: 13-08-2009, 01:57 PM
  4. How to create, deploy and use DB2 stored procedure
    By garfield1 in forum Software Development
    Replies: 3
    Last Post: 08-08-2009, 11:10 AM
  5. How to Write stored procedure in SQL Server
    By Benito in forum Software Development
    Replies: 3
    Last Post: 03-08-2009, 12:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,730,442.05449 seconds with 17 queries