Merging date fields with "if" condition

S

Scott

Hello,

I need some help reformatting data within a query. Here's an example of my
situation.

Table 1:
Field 1 (Month): 4
Field 2 (Year): 2008
Field 3 (Sales): $10,000

Desired Query Output:
I need one date field and one data field containing sales. The problem is
that I always need the date field to contain six characters regardless of the
month. So for the table above, I need: Field 1: 200804 and Field 2: $10,000.
If the month was December, I'd merely merge the date fields to show Field 1:
200812 and Field 2: $10,000.

Questions:
1. How do I merge month and year from two fields in my table to one field
within my query?
2. How do I add the condition, "If month is one digit such as '4,' add a
zero so that the date reads 200804?

Thanks in advance for your assistance.

Scott
 
B

Bob Barrows [MVP]

Scott said:
Hello,

I need some help reformatting data within a query. Here's an example
of my situation.

Table 1:
Field 1 (Month): 4
Field 2 (Year): 2008
Field 3 (Sales): $10,000

Desired Query Output:
I need one date field and one data field containing sales. The
problem is that I always need the date field to contain six
characters regardless of the month. So for the table above, I need:
Field 1: 200804 and Field 2: $10,000. If the month was December, I'd
merely merge the date fields to show Field 1: 200812 and Field 2:
$10,000.

Questions:
1. How do I merge month and year from two fields in my table to one
field within my query?
2. How do I add the condition, "If month is one digit such as '4,'
add a zero so that the date reads 200804?

Thanks in advance for your assistance.

This should work:

Select [Year] & Right("0" & [Month],2) As SalesMonth, Sales From ...
 

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