Click here to Skip to main content
Rate this: bad
good
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 10:35am
Comments
mrinal_kumar_jha at 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 at 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 at 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 at 11-Feb-13 16:06pm
   
can u plzz give me solution with help of union..
Matej Hlatky at 11-Feb-13 16:15pm
   
Just copy first two lines from Volodymyr's code :)
mrinal_kumar_jha at 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 at 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
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 295
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
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