By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 1,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Sql If

100+
P: 158
I am in desperate need to know how to do a simple IF statement in access 2007 sql. ie.

if( check = true) then tbl1.col1 = (tbl1.col1*tbl2.col2)

thank you for any help
Apr 27 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 553
I am in desperate need to know how to do a simple IF statement in access 2007 sql. ie.

if( check = true) then tbl1.col1 = (tbl1.col1*tbl2.col2)

thank you for any help
Hi

You cant execute sql just like this.

To change a value in a table, you need to run sql query. You can use RecordSet or you can also use Execute command to run your query.

If , with your code:
Expand|Select|Wrap|Line Numbers
  1. if( check = true)
  2.  
you are trying to find out a check-box on your form is selected or not, then the syntax would be something like this.
Expand|Select|Wrap|Line Numbers
  1. If checkBoxName = -1  Then    //(-1 means it is selected) 
  2.    // Do something
  3.  
Hope it helps
Qi
Apr 27 '08 #2

Expert 100+
P: 374
I am in desperate need to know how to do a simple IF statement in access 2007 sql. ie.

if( check = true) then tbl1.col1 = (tbl1.col1*tbl2.col2)

thank you for any help
Do so that within an SQL Statement in Access you would do the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Calc:=IIF(tbl1.checkboxname=true,tbl.col1*tbl2.col2,0) FROM tbl1 LEFT JOIN tbl2 ON tbl1.ID = tbl2.LinkID
  3.  
  4.  
You're going to have to have some primary key (i.e. ID) in tbl1 and a Linking ID that will relate the Primary ID in Table 1 to a Reference Key value in Table 2. This way you can have all the child records related to the Parent record all associated together. If there is a One to one relationship, then you'll need to replace LEFT JOIN with INNER JOIN and have the common ID's between the two tables be the same.

Hope that helps,

Joe P.
Apr 28 '08 #3

NeoPa
Expert Mod 15k+
P: 31,186
You've probably got this from the other posts, but SQL doesn't support an IF statement.

What it can handle is returning different values based on a condition. This is done within the IIf() function. The syntax is basically :
Expand|Select|Wrap|Line Numbers
  1. IIf(Condition, ValueIfTrue, ValueIfFalse)
Apr 30 '08 #4

Post your reply

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