Is the CASE statement allowed when querying an Access database?
Assuming so, what is the correct syntax?
thanks
SELECT OrderNo, Description, Type, Label
FROM Stock
WHERE Manuf = 'M'
ORDER BY
CASE 'C' WHEN 'orderno_asc' THEN OrderNo END ASC,
CASE 'C' WHEN 'description_as c' THEN Description END ASC,
CASE 'C' WHEN 'type_asc' THEN Type END ASC,
CASE 'C' WHEN 'label_asc' THEN Label END ASC,
CASE 'C' WHEN 'orderno_asc' THEN OrderNo END DESC,
CASE 'C' WHEN 'description_as c' THEN Description END DESC,
CASE 'C' WHEN 'type_asc' THEN Type END DESC,
CASE 'C' WHEN 'label_asc' THEN Label END DESC 4 1442
shank wrote: Is the CASE statement allowed when querying an Access database?
You could have found out much quicker by using Access online help, but no,
CASE is not supported by JetSQL.
Assuming so, what is the correct syntax? thanks
SELECT OrderNo, Description, Type, Label FROM Stock WHERE Manuf = 'M' ORDER BY CASE 'C' WHEN 'orderno_asc' THEN OrderNo END ASC,
?? What is 'C'? As written, it's a literal string that will never be equal
to 'orderno_asc'.
You have to use the VBA Iif() function, also known as "Immediate If".
Assuming 'C' is actually intended to represent a parameter, here is how it
would look:
Iif([C] = 'orderno_asc',O rderNo,0) ASC,
....
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
"shank" <sh***@tampabay .rr.com> wrote in message
news:ur******** *****@TK2MSFTNG P11.phx.gbl... Is the CASE statement allowed when querying an Access database? Assuming so, what is the correct syntax? thanks
SELECT OrderNo, Description, Type, Label FROM Stock WHERE Manuf = 'M' ORDER BY CASE 'C' WHEN 'orderno_asc' THEN OrderNo END ASC, CASE 'C' WHEN 'description_as c' THEN Description END ASC, CASE 'C' WHEN 'type_asc' THEN Type END ASC, CASE 'C' WHEN 'label_asc' THEN Label END ASC, CASE 'C' WHEN 'orderno_asc' THEN OrderNo END DESC, CASE 'C' WHEN 'description_as c' THEN Description END DESC, CASE 'C' WHEN 'type_asc' THEN Type END DESC, CASE 'C' WHEN 'label_asc' THEN Label END DESC
In addition to the IIF function Bob mentioned, you may also want to
investigate the SWITCH function. The nested IIF functions could get pretty
hairy in this particular situation. Bob, haven't we had this conversation
before? :) http://groups.google.com/groups?selm...TNGP09.phx.gbl
-Chris Hohmann
Chris Hohmann wrote: "shank" <sh***@tampabay .rr.com> wrote in message news:ur******** *****@TK2MSFTNG P11.phx.gbl... Is the CASE statement allowed when querying an Access database? Assuming so, what is the correct syntax? thanks
SELECT OrderNo, Description, Type, Label FROM Stock WHERE Manuf = 'M' ORDER BY CASE 'C' WHEN 'orderno_asc' THEN OrderNo END ASC, CASE 'C' WHEN 'description_as c' THEN Description END ASC, CASE 'C' WHEN 'type_asc' THEN Type END ASC, CASE 'C' WHEN 'label_asc' THEN Label END ASC, CASE 'C' WHEN 'orderno_asc' THEN OrderNo END DESC, CASE 'C' WHEN 'description_as c' THEN Description END DESC, CASE 'C' WHEN 'type_asc' THEN Type END DESC, CASE 'C' WHEN 'label_asc' THEN Label END DESC
In addition to the IIF function Bob mentioned, you may also want to investigate the SWITCH function. The nested IIF functions could get pretty hairy in this particular situation. Bob, haven't we had this conversation before? :)
http://groups.google.com/groups?selm...TNGP09.phx.gbl
Guilty. I forgot about Switch again. However, in this case I do not think it
is appropriate unless all those columns have the same datatype.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:Oe******** ******@TK2MSFTN GP11.phx.gbl... Chris Hohmann wrote: "shank" <sh***@tampabay .rr.com> wrote in message news:ur******** *****@TK2MSFTNG P11.phx.gbl... Is the CASE statement allowed when querying an Access database? Assuming so, what is the correct syntax? thanks
SELECT OrderNo, Description, Type, Label FROM Stock WHERE Manuf = 'M' ORDER BY CASE 'C' WHEN 'orderno_asc' THEN OrderNo END ASC, CASE 'C' WHEN 'description_as c' THEN Description END ASC, CASE 'C' WHEN 'type_asc' THEN Type END ASC, CASE 'C' WHEN 'label_asc' THEN Label END ASC, CASE 'C' WHEN 'orderno_asc' THEN OrderNo END DESC, CASE 'C' WHEN 'description_as c' THEN Description END DESC, CASE 'C' WHEN 'type_asc' THEN Type END DESC, CASE 'C' WHEN 'label_asc' THEN Label END DESC
In addition to the IIF function Bob mentioned, you may also want to investigate the SWITCH function. The nested IIF functions could get pretty hairy in this particular situation. Bob, haven't we had this conversation before? :)
http://groups.google.com/groups?selm...TNGP09.phx.gbl Guilty. I forgot about Switch again. However, in this case I do not think
it is appropriate unless all those columns have the same datatype.
The return value of the SWITCH function is variant so I think we're ok. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Taylor |
last post by:
I have a ListCtrl with 5 columns. The first 4 columns are either
strings or integers, but the last column is a string in the format of
MM-DD-YYYY. I searched google and also read over the
ColumnSorterMixin code & examples, but still can not figure out how to
to write a user-defined sort routine just for the last column in order
to sort that column by date. I still want the sorting of the first
four columns to work as expected. How is...
|
by: Karlo Swart via .NET 247 |
last post by:
Hi.
I am creating a dynamic datagrid. The columns are based on a request.querystring value. Eg: I will pass in a 'func=toys' parameter, which will cause the datagrid to load create columns specific to a toys xml file I pass in.
I have a problem with the sort functionality. I have created the sorting command handler and this works fine when the columns are not created dynamically.
I successfully create the columns for the datagrid in the...
|
by: pmud |
last post by:
Hi,
I am using teh following code for sorting the data grid but it doesnt work.
I have set the auto generate columns to false. & set the sort expression for
each field as the anme of that field... This grid displayes results based on
users search..
public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
|
by: rkbnair |
last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true.
When clicking on the column header, the page refreshes. However the sorting
is not done. Am I missing anything?
I populate the data if !postback.
|
by: Owen T. Soroke |
last post by:
Using VB.NET
I have a ListView with several columns.
Two columns contain integer values, while the remaining contain string
values.
I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.
| |
by: Nathan Franklin |
last post by:
Hello Guys,
I have been trying to work this our for so long, but I just can't seem to
find the answer.
I am loading a datatable from a an access database using an
oledbdataadapter. I then assign the datatable.dataview to my
datagrid.datasource member so it will display my results..
I need to give the user an option to change the order of this data, I have a
|
by: nn0410 |
last post by:
I have a report whose record source is a query. The query includes an
ORDER BY clause that sorts on a particular set of columns. I would
like to be able to run the same report with the same input data, sorted
on a different set of columns. Aside from copying (^C, ^V) the report
and changing the Record Source property in the new copy to another
query, is there an elegant way to accomplish this?
Thanks
Rick
|
by: jediknight |
last post by:
Hi,
I have a listview which has columns of text and columns of numerical
data.
I need to be able to sort these columns into ascending/desending order
whenever the user clicks on the column header.
The text columns are sorted correctly but the numerical columns seem
not to get sorted properly.
For example I get the following result when I try to sort a numerical
|
by: Ahmed Yasser |
last post by:
Hi all,
i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps:
1. i have a datagridview with two columns (LoginName,UserName)
2. the datagridview sorting is set to automatic, so when i click on the column header is sorts well.
3. i put in an event handler for the CellEndEdit Event, so whenever the user of the program changes the content of a cell in the LoginName...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes.
There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)?
Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html
Here is some jquery js that I think...
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |