473,465 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom sorting in sql query

13 New Member
Hello,
I learn SQL SERVER.

I wrote:

SELECT
"All"
UNION SELECT DISTINCT
KindsColumn From ProductsTable

I obtain:
----------------------
1. AA_kind
2. AB_kind
3. All
4. B_kind
5. Z_kind

But i take it into DropDownList where 'All' should be at the top.

I would like to obtain (where 2-5 are sorted)
---------------------------
1. All
2. AA_kind
3. AB_kind
4. B_kind
5. Z_kind

Thank You fot the answer. It will be nice lesson for me.
Apr 24 '10 #1
3 3748
robjens
37 New Member
Ah. I had to see for a bit what you wanted exactly. Thought at first you wanted capital and small case letters sorted in a certain sequence. This kind of "sorting" you won't get the result though. I assume you'd want "All" as the value of a ComboBox/dropdown list to have it run a function lateron perhaps? Else I don't see any reason you'd have that value "All" in there, just add it later to a control using .Add method. If it's pure database we are talking here, you will need to add another field integer type and sort on that like All (1) AA_kind (2) etc. Then just hide the column. You'd still be able to sort on the ABC just enforce All to the top.
Apr 25 '10 #2
mafaisal
142 New Member
@pb2000
That Means,

Expand|Select|Wrap|Line Numbers
  1. Select fld From (
  2. Select 1 Flag,'All' Fld Union All Select 2 Flag, KindsColumn fld 
  3. From ProductsTable ) a 
  4. Order by Flag,Fld
  5.  
  6.  
This may be help you

Faisal M A
Apr 25 '10 #3
ck9663
2,878 Recognized Expert Specialist
Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT 0 as sortorder,
  2. "All"
  3. UNION SELECT DISTINCT 1 as sortorder
  4. KindsColumn From ProductsTable
  5. order by 1, 2
  6.  
Happy Coding!!!

~~ CK
Apr 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Marri Suliez | last post by:
Has anyone found some documentation on how to properly subclass a ListBox control and provide custom sorting (when the list items come from a DataSource)? The only way I can figure out how to do...
0
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
2
by: luca varani | last post by:
I would like to sort the results of a crosstab query by the aggregate function it automatically generates (total of the values in each column of the crosstab). If I simply put "ascending" in the...
22
by: TC | last post by:
I have an Access database application with a lot of custom row functions written in VBA. In other words, a lot of queries contain calculated fields which use functions defined in the modules. I...
1
by: melanieab | last post by:
Hi, I found an article that explains how to do the custom sorting. Here is what it says: .... Perhaps you want some custom sorting method to take effect. To do that, DataGrid provides you with...
0
by: Roy | last post by:
Hey all, I must be losing my touch. I have made many pages in the 1.1 framework that utilize custom bidirectional paging in datagrids. We've converted over to 2.0 and I've been trying to use the...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
3
by: Logu Krishnan | last post by:
in short, the question is "How do i do custom paging in my asp.net grids" in SQL 2000. if i use default paging and if my db has ~200000 records, then i have to select all the 2 lac records then...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
0
by: =?Utf-8?B?QVZM?= | last post by:
Hi, I've a requirement in which I want to use the custom sorting.. I mean I've a dropdown with sortable column names and when the user selects the particular column from dropdown , I need to sort...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.