Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case with order by

Author  Topic 

renjithgr
Starting Member

7 Posts

Posted - 2008-09-18 : 02:48:14
Can anybody help me that for different select options as follows
___ Name
___ Age
___ Address
___ Place

how I will arrange this in sort order according to user enters and which i need to select from a database file.

Like select * from table where conditions order by ???????????

How I can handle this situation?

Regards,
Renjith

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 03:37:45
[code]select * from table
where conditions
order by case when @sort='Name' then Name
when @sort='Address' then Address
when @sort='Place' then Place
...
end[/code]
Go to Top of Page

renjithgr
Starting Member

7 Posts

Posted - 2008-09-18 : 03:45:10
It is not working. The @sort is need to define and to compare with file fields. So if I select 1 on name, 2 on address, 3 on age and 4 on place it will not sort accordingly.
Where to define @sort also..

If I am wrong please correct me?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-18 : 03:46:55
quote:
Originally posted by renjithgr

It is not working. The @sort is need to define and to compare with file fields. So if I select 1 on name, 2 on address, 3 on age and 4 on place it will not sort accordingly.
Where to define @sort also..

If I am wrong please correct me?


can you post your query here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

renjithgr
Starting Member

7 Posts

Posted - 2008-09-18 : 03:50:37
Here the name, address,age and place are screen fields. Table fields are tname, taddress,tage and tplace. So if I need to sort these field in different order according to the user enters in different time.

Can u guide me to resolve this?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 03:54:06
quote:
Originally posted by renjithgr

Here the name, address,age and place are screen fields. Table fields are tname, taddress,tage and tplace. So if I need to sort these field in different order according to the user enters in different time.

Can u guide me to resolve this?


what will you be passing as values while selecting sort column? will it be numeric values like 1,2,.. or screennames like name,address,age,..
Go to Top of Page

renjithgr
Starting Member

7 Posts

Posted - 2008-09-18 : 05:12:03
The sort column values will be nuemeric like 1,2,3 etc
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-19 : 03:33:16
continue over http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=110956


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -