I'm just trying to order some data correctly. In that respect, I've got the following SELECT statement...
SELECT * FROM BKMASTER WHERE MATKEY='MCCOECO' ORDER BY MEDSTA ASC
The thing is, there are only about 5 two-digit options for MEDSTA: NULL, "OE" "OP" "RT", etc. I want any records with blank MEDSTAs to come first, then records where MEDSTA='RT' to come second, then whatever else. I've tried a few different things, but who am I fooling? I don't have a clue how to do this!
Much appreciated.
4 1058
So you need to sort in descending order but thye problem with that is the null's come at the end and you want them at the top.
Try this -
SELECT *
-
FROM BKMASTER
-
WHERE MATKEY='MCCOECO'
-
ORDER BY isnull(MEDSTA,'zzzzzz') ASC
-
try this: -
SELECT * FROM BKMASTER
-
WHERE MATKEY='MCCOECO'
-
ORDER BY
-
case
-
when MEDSTA is null then space(5)
-
when MEDSTA = 'RT' then '0' + MEDSTA
-
else '1' + MEDSTA end ASC
-
-- CK
delerna,
You that's right, but see I need to order them by NULL first, then by which ones say "RT" after than, then by "OE", then whatever's left...
I tried your code (although like I said I only know the real basics so I wasn't entirely sure what to put in place of the ZZZZs) and it threw an "unknown token" code right after isnull. It didn't recognize the (
delerna,
You that's right, but see I need to order them by NULL first, then by which ones say "RT" after than, then by "OE", then whatever's left...
I tried your code (although like I said I only know the real basics so I wasn't entirely sure what to put in place of the ZZZZs) and it threw an "unknown token" code right after isnull. It didn't recognize the (
You have to sure which one would you want as top 3.
Null, RT and OE then the rest? -
SELECT * FROM BKMASTER
-
WHERE MATKEY='MCCOECO'
-
ORDER BY
-
case
-
when MEDSTA is null then space(5)
-
when MEDSTA = 'RT' then '0' + MEDSTA
-
when MEDSTA = 'OE' then '1' + MEDSTA
-
else '2' + MEDSTA end ASC
Sign in to post your reply or Sign up for a free account.
Similar topics
by: LRW |
last post by:
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
Here's what I have:
function checkdel() {
if...
|
by: TokiDoki |
last post by:
Hello there,
I have been programming python for a little while, now. But as I am
beginning to do more complex stuff, I am running into small organization
problems.
It is possible that what I...
|
by: Tim::.. |
last post by:
Can someone tell me how I convert this simple SQL statement so I can use it
in ASP.NET???
I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql...
|
by: Scott Frankel |
last post by:
Still too new to SQL to have run across this yet ...
How does one return the latest row from a table, given multiple entries
of varying data?
i.e.: given a table that looks like this:
color...
|
by: Brian Tkatch |
last post by:
An ORDER BY a simple-integer inside a FUNCTION, results in SQL0440N,
unless the FUNCTION expects an INTEGER as its parameter. For example:
DECLARE GLOBAL TEMPORARY TABLE A(A CHAR(1))
INSERT INTO...
|
by: gjoneshtfc |
last post by:
Hello, I have a simple problem that I just cannot get my head around!
I currently have the following line in my ASP recordset:
Recordset1.Source = "SELECT * FROM MainTable ORDER BY Price ASC"...
|
by: firstcustomer |
last post by:
Hi,
Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that
someone will be able to point me to a ready-made solution to my
problem!
A friend of mine (honest!) is wanting to...
|
by: Ganesh Muthuvelu |
last post by:
Hello all,
I have a XML as below:
******************
<BLOCK>
<ROW1>
<A>1</A>
<B>2</B>
</ROW1>
<ROW2>
|
by: SoulScriber |
last post by:
This comes to be an IE vs. Firefox issue.
What I'm trying to do is 'onchange' of a checkbox have a table display underneath.
Firefox works fine (when you click on the 'Check Here if your...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
| |