Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using If-Then in Query - Can I?

Status
Not open for further replies.

wirewendy

Programmer
Jun 14, 2001
1
US
We are trying to change the parameters of a query based on what day it is today.

If it is Tuesday, do this.
If it is Wednesday, do this.

What syntax do we use?
 
There are some options available but without more info it is impossible to say what you need to do. Let me give you some posibilities.

Use datepart("w",date()) to get the day of the week where 1=Sun, 2=Mon, 3=Tue, ...

You can use the Choose function in conjunction with datepart to determine some values.

Choose(datepart("w",date()),'Sun value','Mon value', ..., 'Sat value')

You can write a function in VBA and use the function in a query. In this case I use the Select Case statement.

Function DetermineValue ()

Select Case datepart("w",date())
Case 1
<Case 1 logic>
DetermineValue = SundaySales 'just a sample
Case 2
<Case 2 logic>
Case 3
<Case 3 logic>
.
.
.
Case Else
msgbox &quot;What? Not a day of the week!&quot;
End Select

End Function

Hope these help a little. Terry

The reason why worry kills more people than work is that more people worry than work. - Robert Frost
 
Another alternative would be to use
Code:
iif(datepart(&quot;w&quot;,date())=3,&quot;Yippee it's Tuesday&quot;,&quot;Not Tuesday today then&quot;)
but this may not exactly be the logic you want (only gives you alternatives for 'Tuesday' or 'not Tuesday'). However, you can use it direct in an SQL query.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top