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.
| Author |
Topic |
|
AdamWest
Constraint Violating Yak Guru
360 Posts |
Posted - 2010-03-12 : 13:56:19
|
| HI I would appreciate any thoughts on how to do this.I have a front end combo box that displays all the customers of a user. The program as it works, just starts to display the first customer that is displayed in the combo box. You login and then are directed to a page with some tabs, when you choose the tab of this program it just starts with that first customer.They would like to have each user, to be able to designate which customer is their default.so that then when the user logs in, when I fetch their customers via the SQL, it would order it normally except that the first one has to be the default.AS far as the display part, one way I thought of is to have a special view for each user. But how do I tell the SQL to have a particular customer be first.I do not mind to hard code this thing, but perhaps a better way is to have a table for this purpose that would have the default cust. for each user.I would appreciate any comments on the approach to do this. |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2010-03-12 : 14:06:28
|
| so you want a different default customer for each user on the top in the list of customersdefault customercustomer 1customer 2customer 3etc...have a order by with case statement. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-13 : 02:08:59
|
what you can do in that case is have a table with userid and defaultcustid, then in your retrieval query useSELECT columns....FROM(SELECT othercolumns....,CASE WHEN t.defaultcustid IS NOT NULL THEN 1 ELSE 0 END AS SortOrd(your current query) qLEFT JOIN DefaultCustTable tON t.userid = q.useridAND t.defaultcustid = q.custid)tORDER BY SortOrd DESC,other columns in current order by... ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|