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
 Positioning a table for display

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 customers

default customer
customer 1
customer 2
customer 3
etc...

have a order by with case statement.
Go to Top of Page

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 use

SELECT columns....
FROM
(
SELECT othercolumns....,
CASE WHEN t.defaultcustid IS NOT NULL THEN 1 ELSE 0 END AS SortOrd
(your current query) q
LEFT JOIN DefaultCustTable t
ON t.userid = q.userid
AND t.defaultcustid = q.custid
)t
ORDER BY SortOrd DESC,other columns in current order by...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -