473,387 Members | 1,844 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,387 software developers and data experts.

does Access have a FIELD() or identical SQL function

ronverdonk
4,258 Expert 4TB
Does Access have a FIELD() function or something alike. I want to sort my query result in a non-standard order by specifying e.g.
Expand|Select|Wrap|Line Numbers
  1. SELECT * from table_name ORDER BY FIELD(col_name, 'You', 'Me', 'We', 'They')
I use this frequently in MySQL, but I could not find a similar function in MS Access documentation (but I am short sighted and could have overlooked it :-)

Thanks in advance,

Ronald
Mar 30 '08 #1
5 1715
ADezii
8,834 Expert 8TB
Does Access have a FIELD() function or something alike. I want to sort my query result in a non-standard order by specifying e.g.
Expand|Select|Wrap|Line Numbers
  1. SELECT * from table_name ORDER BY FIELD(col_name, 'You', 'Me', 'We', 'They')
I use this frequently in MySQL, but I could not find a similar function in MS Access documentation (but I am short sighted and could have overlooked it :-)

Thanks in advance,

Ronald
To the best of my knowledge, there is no equivalent functionality in Access but I'm sure you can improvise. I'm not familiar with the Field() Function in MySQL, so bear with me on this one.
  1. Are You, Me, We, and They the only possible values contained within [col_name]?
  2. I'm assuming you want the vales in [col_name] sorted by 'You', 'Me', 'We', and 'They'. Is this correct? If so, the solution would be simple enough.
  3. If I'm off track, I apologize, please fill me in.
Mar 30 '08 #2
ronverdonk
4,258 Expert 4TB
To the best of my knowledge, there is no equivalent functionality in Access but I'm sure you can improvise. I'm not familiar with the Field() Function in MySQL, so bear with me on this one.
  1. Are You, Me, We, and They the only possible values contained within [col_name]?
  2. I'm assuming you want the vales in [col_name] sorted by 'You', 'Me', 'We', and 'They'. Is this correct? If so, the solution would be simple enough.
  3. If I'm off track, I apologize, please fill me in.
I am definitely sure I can improvise, but it would have been nice to let SQL engine do the work for me.

The values specified in the FIELD list will always be first in the result set. Any column values that do not comply with the speficied values will be sorted in the standard way, but shown in the result set after the specified values. So the result would be (simplified):
Expand|Select|Wrap|Line Numbers
  1. You
  2. Me
  3. We
  4. They 
  5. All of us
  6. He
  7. She
  8. Whoever
Ronald
Mar 30 '08 #3
ADezii
8,834 Expert 8TB
I am definitely sure I can improvise, but it would have been nice to let SQL engine do the work for me.

The values specified in the FIELD list will always be first in the result set. Any column values that do not comply with the speficied values will be sorted in the standard way, but shown in the result set after the specified values. So the result would be (simplified):
Expand|Select|Wrap|Line Numbers
  1. You
  2. Me
  3. We
  4. They 
  5. All of us
  6. He
  7. She
  8. Whoever
Ronald
Gotcha. My 'improvised' solution would have been:
  1. Create a [Priority] {INTEGER} Field in your Table.
  2. Dynamically Update this Field to the following values:
    1. If [col_name] = 'You', set [Priority] = 1.
    2. If [col_name] = 'Me', set [Priority] = 2.
    3. If [col_name] = 'We', set [Priority] = 3.
    4. If [col_name] = 'They', set [Priority] = 4
    5. Remaining values in [Priority] would be assigned Priority Levels (>4) based on their natural Sort Order (code not shown).
    6. Create a Query with the Primary Sort Order of [Priority]/Ascending.
  3. I don't think that this can be accomplished by pure SQL, but NeoPa would be the one to see for that. I'll call him in on this.
  4. Sorry I couldn't be more helpful.
Mar 30 '08 #4
ronverdonk
4,258 Expert 4TB
No sweat. I just wanted to know if it was possible in Access.
Now I do the same (array) sort in my PHP result set, along the lines you showed.

Ronald
Mar 30 '08 #5
NeoPa
32,556 Expert Mod 16PB
I've never come across such functionality I'm afraid Ron. I don't believe it exists as standard in Access Jet SQL :(

Access can't handle this easily at all I'm afraid. My personal preference, if faced with such an issue, would be to design a public function procedure in VBA which would evaluate the parameter and return a string value that would sort normally.

I couldn't get the Switch() function to work sensibly as there is no finite list.
Mar 31 '08 #6

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
0
by: Steve | last post by:
Greetings, I'm having problems with the use of an Access 2003 Add-In on Windows XP Pro. Administrative-level users have no problems running the Add-In, but those users with restricted rights on...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
4
by: martin | last post by:
Can anyone please help. I have a main membership form/table that has a subform with function table linked. This is obviously a fixed solution but I would like to make it more dynamic with a combo...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
8
by: PW | last post by:
Hi, There is code in Alison Balter's excellant "Mastering Access 2003" to create a list of error codes and descriptions but it only generates error messages 3 through 94. Is there a website...
7
by: preeny8 | last post by:
Hi there, I recently updated to Access 2007, and I'm getting a couple of errors that i'm not sure how to deal with. I worked with a lot of databases in Access 2003 (.mdb), and for some reason...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.