Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > sorting columns with Access

Reply
Thread Tools

sorting columns with Access

 
 
shank
Guest
Posts: n/a
 
      07-20-2004
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_asc' 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_asc' THEN Description END DESC,
CASE 'C' WHEN 'type_asc' THEN Type END DESC,
CASE 'C' WHEN 'label_asc' THEN Label END DESC


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-20-2004
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',OrderNo,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.


 
Reply With Quote
 
 
 
 
Chris Hohmann
Guest
Posts: n/a
 
      07-20-2004
"shank" <> wrote in message
news:ur0$...
> 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_asc' 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_asc' 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


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-21-2004
Chris Hohmann wrote:
> "shank" <> wrote in message
> news:ur0$...
>> 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_asc' 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_asc' 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.


 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      07-21-2004
"Bob Barrows [MVP]" <> wrote in message
news:...
> Chris Hohmann wrote:
> > "shank" <> wrote in message
> > news:ur0$...
> >> 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_asc' 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_asc' 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Align table columns with gridview columns Jacksm ASP .Net 2 11-21-2006 09:49 PM
Read CSV - string Columns - Int columns =?Utf-8?B?YmVub2l0?= ASP .Net 0 05-08-2006 02:11 PM
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
CSS columns problem - faux columns don't work henrybranson@hotmail.com HTML 4 11-24-2005 10:05 AM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57