473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Order By one of two possible fields.

dlite922
1,584 Expert 1GB
Hey guys,

I have a list of channels, some represent the same channel but in HD, but these HD's are further down the list. I want to sort them by the actual channel number.

For example if HBO is 300 for Standard Definition and it's high definition is at 9000, I want to see them one after the other instead of landing on different pages.

Sample Data for this example:

id 100
number 300
name HBO
source 0

id 569
number 9000
name HBO HD
source 300


As you can see the HD version's source channel number is the same as the first HBO, 300.

I want to sort by number if source is 0, else by source.

I tried concat() to concatenate the two fields, do a number sort (+0) then take the substring of first three characters so that 3009000 -> 300. But this doesn't work for all my channels because not all of them are three digits.

It would be nice if I could use IF(): if source = 0, number; else source


Any ideas is appreciated as always!




Dan
Mar 23 '09 #1
3 1464
TheServant
1,168 Expert 1GB
I am not sure if the logic is there. What about either making another field to sort by, or change the number for HBO HD to 300. Then you can simply sort by 2 columns. First you sort by number, which would sort it by number and put your HD channels together with the SD ones, and then sort by source which would put your SD's above your HD's because all SD's (I think) have a source of 0? Hope that made sense.
Mar 23 '09 #2
dlite922
1,584 Expert 1GB
SOLVED.

@TheServant
This database has more problems, but alas I'm not in charge of it, I can only "peek" at the data.

For some reason I thought I couldn't do an IF because I read somewhere you can only do it in a stored procedure. but the IF() /function/ did the trick.

SELECT IF(source = 0, number, source) as sortField
...
ORDER BY sortField


Thanks anyhow!




Dan
Mar 23 '09 #3
TheServant
1,168 Expert 1GB
@dlite922
So did I... Hmmm this could be very useful. So thank you Dan ;)
Mar 23 '09 #4

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

Similar topics

39
by: Nicolas Fleury | last post by:
In the following example: class MyMetaclass(type): pass class MyBaseType(object): __metaclass__ = MyMetaclass class MyType(MyBaseType): x = 4 y = 5 z = 6 Is there any way to modify...
3
by: Tim Chmielewski | last post by:
For an auto-generated form I have the following order of fields: savevalues userid productcode PrintColour1_1 Colour1_1 Quantity_1 " " " " " " " ...
2
by: Eduardo Rosa | last post by:
Hi, I need some help... I have a field type date in xml, loading with Microsoft.XMLDOM, how can I order by date? thanks a lot xml code: <Root> <Fields> <Field Id="456955" Date="01/05/1956"...
2
by: Cindy | last post by:
Hi- I've got some issues with the ordering of search results. I've got 4 fields, (1, 2, 3, 4). Most often there is data in field 1. Sometimes there isn't and so then I'd like to look at field...
4
by: Dan | last post by:
I've encountered some strange behavior in a recursive procedure I'm writing for a bill of materials. First let me ask directly if what I think is happening is even possible: It seems like the...
4
by: Tryfon Gavriel | last post by:
Hi all I recently noticed when trying to optimise a major query of a chess website I am the webmaster of, that adding an order by for "gamenumber" which is a clustered index field as in for...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
12
by: Jozef | last post by:
Hello, Does anyone here know for sure, when you do a For Each loop on a forms controls collection, does Access cycle through them in Alphabetical order or control ID or ???. Any ideas? ...
6
by: Index | last post by:
Hi, I have a file which I want to sort depending on multiple columns. Actually I want to implement the following query through programming: SELECT SUM(VALUES) GROUP BY x,y ORDER BY x,y; the...
13
by: Kevin | last post by:
Hi, I have used ASP for years using MS Access and have used MSSQL quite a lot as well. I have never came across something like this before. MSSQL table names and types: ProductName nvarchar...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.