Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter in Order By clause? 1

Status
Not open for further replies.

chris123321

IS-IT--Management
Mar 13, 2007
139
US
A user has a drop-down list in which he can decide how to Group By a report. And the Group-By of the report depends on the Order By clause of the stored procedure. So for each of the different selections in the dropdownlist, the report will look different.

The best solution I found is using a case statement from:
Code:
DECLARE @col VARCHAR(9) 
SET @col = 'firstname' 
 
IF @col IN ('firstname', 'email') 
    SELECT * FROM blat 
        ORDER BY CASE @col 
            WHEN 'firstname' THEN firstname 
            WHEN 'email' THEN email 
        END 
ELSE 
    SELECT * FROM blat 
GO

Any other suggestions?
 
UDF's can be performance killers. It's best to figure out why the derived table isn't working.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Worked perfectly, George..

Thanks for your help. Using the derived table the performance time of the sproc was 2 seconds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top