Using SQL in MS Access 2000

M

mhraja

I am trying to run some SQL script in MS Access 2000 for creating
query. But its not take 'IF' and 'ELSE' command. Can someone guide me
that how can I use IF and Else in MS Access 2000.

Kind Regards,
Muhammad Hasnain Raja
 
D

Douglas J. Steele

You can't use If and Else in Access SQL. However, the IIf function is the
equivalent.

IIf(expr, truepart, falsepart)
 
N

Nano

Thanks for replying. But MS Access is not letting me even use the one
you mentioned. The following messages appears.

Invalid SQL Statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
'SELECT', or 'UPDATE'

How can I procede now ?
 
N

Nano

Or may be I am writing this is wrong way, where should I write this If
condition ?

Kind Regards,
Hasnain Raja
 
D

Douglas J. Steele

It's pretty difficult for me to say without seeing what you're trying to
use, and knowing what you're trying to do.
 
N

Nano

I appolgise for making you confused. What I want to do is that lets
suppose we have two columns name A and B. Column A can have either F
or V. Now if I select F I want a list of fruit in Column B and if I
select V in column A then I want list of vegetables in column B.

I hope now my case is clear to you.

Kind Regards,
Hasnain Raja
 
S

Stefan Hoffmann

hi Nano,
I appolgise for making you confused. What I want to do is that lets
suppose we have two columns name A and B. Column A can have either F
or V. Now if I select F I want a list of fruit in Column B and if I
select V in column A then I want list of vegetables in column B.
SELECT t.*, Iif(t.A = "F"; "Fruit"; "Vegetable")
FROM
t


mfG
--> stefan <--
 
N

Nano

Thanks Stefan, this seems to be a great help to me. I will try using
this.

Kind Regards,
Hasnain Raja

hi Nano,
I appolgise for making you confused. What I want to do is that lets
suppose we have two columns name A and B. Column A can have either F
or V. Now if I select F I want a list of fruit in Column B and if I
select V in column A then I want list of vegetables in column B.

SELECT t.*, Iif(t.A = "F"; "Fruit"; "Vegetable")
FROM
t

mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Hasnain,
Its working and one more thing, Can Vegetable and Fruit be two other
queries too ?
I'm not sure what you mean. Can you explain it?

Maybe

SELECT *
FROM

WHERE A = "F"


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top