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

Adding a yes/no field to a query

P: 2
I have a table that has a bunch of dates in one column and I want to add a column via query to put a yes for everything > today's date and a no for everything < today's date. How do I do that?
Thanks!
Sep 13 '08 #1
Share this Question
Share on Google+
2 Replies


nico5038
Expert 2.5K+
P: 3,072
Best not to add such a column (will be different tomorrow :-)
We use a query for getting this information like:

select DateFieldX, IIF([DateFieldX>Date(),"Future","Past") as StateOfDate from tblX

Getting the idea?

Nic;o)
Sep 13 '08 #2

NeoPa
Expert Mod 15k+
P: 31,345
When you say you want to return Yes or No in your query, if these are simply the inbuilt Yes and No (rather than "Yes" & "No" strings), then the following concept will work for you :
Expand|Select|Wrap|Line Numbers
  1. SELECT [DateFieldX],
  2.        ([DateFieldX]>Date()) AS [AfterToday]
  3.  
  4. FROM [tblX]
Otherwise, Nico's code gives a good template for your requirements, with the balancing closing square bracket (]) after DateFieldX in the IIF() function call (as in my doctored quote below).
Expand|Select|Wrap|Line Numbers
  1. select DateFieldX, IIF([DateFieldX]>Date(),"Future","Past") as StateOfDate from tblX
Sep 14 '08 #3

Post your reply

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