Click here to Skip to main content
12,358,510 members (60,516 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
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..
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 11-Feb-13 9:35am
Comments
mrinal_kumar_jha 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

To have websites with id = 1 and 604 on top of list, you need to alter your ORDER BY clause like this:
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
  Permalink  
Comments
mrinal_kumar_jha 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.
mrinal_kumar_jha 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 :)
mrinal_kumar_jha 11-Feb-13 16:21pm
   
that code is not working
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Probably you need something like this:
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
  Permalink  
Comments
mrinal_kumar_jha 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100