Thursday, January 5, 2012

Sort Record at Sql Querry Level using Store Procedure.......


CREATE PROCEDURE [dbo].[mp_Users_SelectLockedUsers]

@SiteID int,
@SortExpression nvarchar(50)=Null,
@SortDirection nvarchar(50)=Null


SELECT * FROM mp_Users u WHERE
u.SiteID = 1
ORDER BY CASE WHEN @SortExpression='' AND @SortDirection='' Then
u.UserName END,
CASE WHEN @SortExpression='Name' AND @SortDirection='A' Then
u.Name END DESC,
CASE WHEN @SortExpression='Name' AND @SortDirection='D' Then
u.Name END ASC,
CASE WHEN @SortExpression='FirstName' AND @SortDirection='A' Then
u.FirstName END DESC,
CASE WHEN @SortExpression='FirstName' AND @SortDirection='D' Then
u.FirstName END ASC,
CASE WHEN @SortExpression='LastName' AND @SortDirection='A' Then
u.LastName END DESC,
CASE WHEN @SortExpression='LastName' AND @SortDirection='D' Then
u.LastName END ASC,
CASE WHEN @SortExpression='Email' AND @SortDirection='A' Then
u.Email END DESC,
CASE WHEN @SortExpression='Email' AND @SortDirection='D' Then
u.Email END ASC



0 comments:

Post a Comment