Urgent - Create column on query depending on another column text

F

Fred

HI.. i need help on solving one big problem i can't get the solution..
I have a query that gets some values and also a month text from one table..
based on a form parameters.. What i want to do is to add/create a column on
the query and make that column depend on the text of another column..
Like..if the text in colum month is "january" the value should be on column
"num" should be 1, "february" - 2, December - 12....etc

the SQL code i have before creating that column i need is:

SELECT Table1.Ano, Table1.Parque, Table1.[Potência Produzida],
Table1.[Irradiância média], Table1.Temperatura, Table1.[Nº de horas de sol],
Table1.Month, Table1.Tarifa
FROM Table1
WHERE (((Table1.Ano)=[Forms]![Form3].[combo6]) AND
((Table1.Parque)=[Forms]![Form3].[combo4]));

Now i want to create column called "num" and i want to programme it
something like this code(in VBA only to exemplify):

if (query).(column_month).text = "January" then
(column_num).value = 1
else
if (query).(column_month).text = "February" then
(column_num).value = 2
else
if (query).(column_month).text = "March" then
(column_num).value = 3
else
...............................

Please help on how to do it..
Thanks!
Nuno
 
J

Jerry Whittle

Two choices.

Create a Months table with the names of the months in one column and the
number in another. Join this table in the query.

Another is to use something like below to create a date and use the Month
function on it. The year really doesn't matter.
TheMonth: Month([Table1].[Month] & " 1, 2000")

Better yet if you already have a good date field in the table, use the Month
function on it.
 

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