473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

specify a non-linear order by

How can I order the results of my query in non-linear fasion. I have a
field with these values: Reg S, 144A, US and want to order my results
by US, 144A, Reg S.
I would prefer not to create another field in the table if possible.

Jul 23 '05 #1
4 1683
You can do it like this:

....ORDER BY CASE fieldname WHEN 'US' THEN 1 WHEN '144A' THEN 2 WHEN
'Reg S' THEN 3 ELSE 4 END

Alpine7 wrote:
How can I order the results of my query in non-linear fasion. I have a field with these values: Reg S, 144A, US and want to order my results
by US, 144A, Reg S.
I would prefer not to create another field in the table if possible.


Jul 23 '05 #2
Thanks that is exactly what I was looking for works great.

Jul 23 '05 #3
SELECT ..
CHAR_INDEX ('US, 144A, Reg S.') AS sort_col
FROM Foobar
ORDER BY sort_col;

Jul 23 '05 #4
I would point out that, whenever you are repeating a text value in a column of
a table, you should probably be using a surrogate key to a lookup table
instead. Your new requirement for a specific sort order for the codes drives
this point home. If you create a lookup table for your codes, you can add a
sort order attribute to the codes table and not be forced to choose between
adding another column to your main table or using SQL that will be invalid the
next time a code is added.

Example:

paper_type
----------
(pk) paper_type_id int identity
(u) paper_type_code varchar(10)
order_sequence int

document
--------
(pk) document_id
(fk) paper_type_id
document_title

To query from these tables in the document type sort order, ...

SELECT
document.docume nt_title,
paper_type.pape r_type_code
FROM
document
INNER JOIN paper_type
ON document.paper_ type_id = paper_type.pape r_type_id
ORDER BY
paper_type.orde r_sequence
document.docume nt_title

On 9 Dec 2004 07:53:16 -0800, "Alpine7" <da****@datasho ck.com> wrote:
How can I order the results of my query in non-linear fasion. I have a
field with these values: Reg S, 144A, US and want to order my results
by US, 144A, Reg S.
I would prefer not to create another field in the table if possible.


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4085
by: Lasse Edsvik | last post by:
Hello I have a mailserver that requires windows authentication for sending email. could you guys show me an example of how to specify user and password in CDO/CDONTS? i cant configure it to send with no authentication. TIA
12
3266
by: Jim Cochrane | last post by:
I just google-searched this group and could not find any references to this. I'm trying to figure out how to specify a three-part header with html. For example, left part center part right part For old troffists, this is what the .tl construct does. But how would it be done in html? I tried <div align = left>left part</div> <div align = center> ..., which almost worked, except each part is on...
6
77511
by: Tony Marston | last post by:
The code <a href="..." target="_blank">...</a> will not validate as XHTML STRICT because of the 'target' tag, so how do I achieve the same result by moving it to a CSS file? I cannot find anything which allows me to specify 'target=' on an anchor tag. -- Tony Marston http://www.tonymarston.net
1
1508
by: Andrew Biagioni | last post by:
Hi all! I'm trying to write a general-purpose trigger that determines what fields have changed during an UPDATE, but I'm running into a problem. I'm trying to dynamically select the value from a field in "old" and "new" (the old and new values for the changed row), but I can't figure out how to do so. I tried something like,
2
4496
by: Tony | last post by:
Yes, I need to specify a font type so that the characters will be evenly spaced when I write to a tab delimited text file. So how does one specify a font type to write/print and which font is best for evenness?
0
1211
by: Rajiv Das | last post by:
..Net 2.0 --------- Assume I am on a non-domain network. The proxy asks me to authenticate whenever I want to access the net. I have an app, through which I wish to access web sites using HttpWebRequest. Now in the config file snippet below: <system.net> <defaultProxy useDefaultCredentials="false">
0
1074
by: sylvain | last post by:
I create a deployment kit with VS and I want to specify a Web Site different then the Default Web Site. There are two Web Site on our Web Server and they are using the same Port (two different network card). Is there a way to specify the Web Site to deploy my web application ? By default, It's seem to deploy on the Default Web site. I know I can specify the Port but on my case It's the same... Is there a way to specify the Web Site on...
15
3807
by: jacob navia | last post by:
Problem You want to ensure that a pointer argument to a function is non-null. Solution int fn(double data); This means that the array (that is passed as a pointer)
3
2603
by: =?Utf-8?B?Q0QuU21hbGxleQ==?= | last post by:
Is there a command line switch available for the EventViewer which will allow me to specify which directory to view the available logs from? I will have multiple workstations writing to a mirrored set of really large flash drives. The workstations will write to their specific standard .evt files. I need to be able to start EventViewer and specify which workstations's logs to go view at startup. Is this possible w/o creating my own...
2
1590
by: zz12 | last post by:
Hello. Would anyone know if there is an easy and clean way of presenting maybe a time control field in html in an .asp page that allows a user to specify a certain time of the day? Currently using an <input name="SpecifyTime" type="Text"field but was wondering if there was a better way of doing this as to where users won't mistype in entering non time related characters? Thanks in advance.
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4036
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 we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.