Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Every one,

I have the below stored proc:

SQL
CREATE PROC [dbo].[BINDUSERS]
AS
BEGIN
SET NOCOUNT ON
SELECT Uid,UserName FROM UserDetails WHERE RoleId=2
UNION
SELECT 0,'Select'
END


Could any one please tell me how to display the "Username" values in alphabetical order by keeping the value 'Select'
always on top ?

Regards,
Posted
Updated 1-Mar-11 19:11pm
v3

Try this it will work

CREATE PROC [dbo].[BINDUSERS]
AS
BEGIN
SET NOCOUNT ON
Select * from (
SELECT Uid,UserName FROM UserDetails WHERE RoleId=2
UNION
SELECT 0,'All') alluser order by UserName
END


[Edit]
you can use this
SQL
CREATE PROC [dbo].[BINDUSERS]
AS
BEGIN
SET NOCOUNT ON
Select * from (
SELECT Uid,UserName, UserName as ForOrdering FROM UserDetails WHERE RoleId=2
UNION
SELECT 0,'All','~') alluser order by ForOrdering
END



[/Edit]
--Pankaj
 
Share this answer
 
v2
Comments
Raj.rcr 2-Mar-11 0:58am    
This is same as the above one. 'All' should always be on Top in the dropdown list. Thats not possible with this query.
pankajupadhyay29 2-Mar-11 1:07am    
i made change for your requirement.

Have you try this
SELECT 0 as Uid,'All' as UserName
Union
SELECT Uid,UserName FROM UserDetails WHERE RoleId=2 order by UserName.

I am not sure about this but it should work.
Raj.rcr 2-Mar-11 1:07am    
ya.. I tried this also.. Its not working.
pankajupadhyay29 2-Mar-11 1:09am    
what about edited part that must work. have you checked??
Raj.rcr 2-Mar-11 1:12am    
I really tried both.. Its not working.. Please take 'Select' instead of 'All' to avoid the confusion and
suggest me.
Try
SELECT Uid,UserName FROM UserDetails WHERE RoleId=2
UNIONSELECT 0,'All' 
Order by 2
 
Share this answer
 
Comments
Raj.rcr 2-Mar-11 0:55am    
But, 'All' should always be on Top in the dropdown list. Thats not possible with this query.
Raj.rcr 2-Mar-11 1:44am    
Thanx for the answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900