Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 18th, 2003, 09:46 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using A CASE Statement

What is the correct syntax for using a CASE function in a SQL statement that has 4 cases to evaluate when running against an Access 2000 database? In VB the CASE would be as follows:

SELECT CASE Plan
     CASE "MON"
          SupPlan = Amt
     CASE "QUR"
          SupPlan = Amt * 4
     CASE "Ann"
          SupPlan = Amt * 12
     CASE "NON"
          SupPlan = 0
END SELECT

How do I do this same thing with SQL in Access?
Reply With Quote
  #2 (permalink)  
Old December 18th, 2003, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

In SQL:

DECLARE @TestVal int
SET @TestVal = 3

SELECT
    CASE @TestVal
        WHEN 1 THEN 'First'
        WHEN 2 THEN 'Second'
        WHEN 3 THEN 'Third'
        ELSE 'Other'
    END



Reply With Quote
  #3 (permalink)  
Old December 18th, 2003, 12:30 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't declare variables in a SQL statement that is going to be used against an Access database. The syntax I am looking for will have to be one long line that can be run against the Microsoft Jet 4.0 engine.
Reply With Quote
  #4 (permalink)  
Old December 21st, 2003, 06:53 AM
Authorized User
 
Join Date: Nov 2003
Location: Paola, Europe, Malta.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why don't you put your code in a function within a Standard module and invoke it from a query or SQL statement?
Reply With Quote
  #5 (permalink)  
Old December 24th, 2003, 01:56 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I didn't know you could access a VB function with SQL in Access 2000. How do you do that? I have no idea how to create a SQL statement that would reference a function in a VB module.
Reply With Quote
  #6 (permalink)  
Old December 24th, 2003, 01:39 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Go to modules, add new and put in a public function:
Code:
Public Function GetNow() As Date

  GetNow = Now()
End Function
This one duplicates an existing function but you can do more or less anything.



--

Joe
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case statement cole SQL Language 3 May 8th, 2005 03:02 PM
case statement Hudson40 Access VBA 1 February 11th, 2005 11:31 AM
case statement troubles!! ronny Classic ASP Databases 2 April 10th, 2004 07:32 PM
HELP - IF ELSE & CASE statement savoym SQL Language 3 September 12th, 2003 06:35 AM
case statement jakeone Beginning PHP 10 August 19th, 2003 03:03 PM



All times are GMT -4. The time now is 10:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.