Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT in_website_id, in_website_type_id, vc_website_name, vc_login_name FROM dbo.website

    WHERE bt_active = @bt_active ORDER BY vc_website_name



Using given query i am binding dropdown like this..
C#
if (dtWebsite.Rows.Count > 0)
    {
      ddlWebsite.DataSource = dtWebsite;
      ddlWebsite.DataTextField = "vc_website_name";
      ddlWebsite.DataValueField = "in_website_id";
      ddlWebsite.DataBind();
      ddlWebsite.Items.Insert(0, new ListItem("Select Website", "0"));



Here i want to show two in_website_id(1 and 604) to top How to achieve this in sql
Posted
Comments
k@ran 11-Feb-13 15:37pm    
website id with 1 and 604 should come first in dropdown and rest as comes ORDER BY vc_website_name

To have websites with id = 1 and 604 on top of list, you need to alter your ORDER BY clause like this:
SQL
SELECT
    in_website_id, in_website_type_id, vc_website_name, vc_login_name
FROM
    dbo.website
WHERE
    bt_active = @bt_active
ORDER BY
    (CASE WHEN in_website_id IN (1, 604) THEN 0 ELSE 1 END),
    vc_website_name
 
Share this answer
 
Comments
k@ran 11-Feb-13 15:55pm    
@Matej Hlatky : It is working but i cant understand statement after case how it works fine.. Can you plzz explain how this query works
Matej Hlatky 11-Feb-13 16:14pm    
For sites with id = 1 and 604 it returns 0, for other else 1. Since 0 is before 1, these sites are on top of sorted list.
k@ran 11-Feb-13 16:06pm    
can u plzz give me solution with help of union..
Matej Hlatky 11-Feb-13 16:15pm    
Just copy first two lines from Volodymyr's code :)
k@ran 11-Feb-13 16:21pm    
that code is not working
Probably you need something like this:
SQL
SELECT 0, null, 'Select Website', null
UNION ALL
SELECT in_website_id, in_website_type_id, vc_website_name, vc_login_name FROM dbo.website
WHERE bt_active = @bt_active ORDER BY vc_website_name
 
Share this answer
 
Comments
k@ran 11-Feb-13 15:50pm    
i want two website id at first , plzz provide query..

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