Ouerie Year(Now())-1 Or Year(Now())

  • Thread starter Thread starter theresa73
  • Start date Start date
T

theresa73

Hej!

Har en fråga, har en querie där jag skrivit i criteria Year(Now())-1
Or Year(Now()). När jag kör frågan får jag upp info om en medlem
för året 2006 och 2005. Är det möjligt att bara ha den ena eller
den andra. Allså om jag redan har information av en medlen för året
2006 då behöver jag inte 2005. Men om det inte finns någon info för
året 2006 då vill jag ha upp 2005.

Vet inte riktigt hur jag ska förklara :) men hoppas ni förstår.

Tack på förhand.

TC
 
Hi,
If I understand correctly, you want to query some data for the year 2006,
and if there is no data for that year, return the data for 2005 instead.

Is this correct?

James

Hej!

Har en fråga, har en querie där jag skrivit i criteria Year(Now())-1
Or Year(Now()). När jag kör frågan får jag upp info om en medlem
för året 2006 och 2005. Är det möjligt att bara ha den ena eller
den andra. Allså om jag redan har information av en medlen för året
2006 då behöver jag inte 2005. Men om det inte finns någon info för
året 2006 då vill jag ha upp 2005.

Vet inte riktigt hur jag ska förklara :) men hoppas ni förstår.

Tack på förhand.

TC
 
Hello James, thank you for repling to my question.
That is correct. Is there a way to do this?
TC
 
Hello James, thank you for repling to my question.
That is correct. Is there a way to do this?
TC

Its not very elegant but here goes:
If you have "Table1" with a date/time field called "TheDate" and a text
field called "Name" you could use the following (with a subquery):

SELECT Table1.TheDate, Table1.Name
FROM Table1
WHERE ((((SELECT Max(Year([TheDate]))
FROM Table1
WHERE Year([TheDate]) >= (Year(now)-1)))=Year([TheDate])));

It selects the rows from the table whose year is the same as the latest year
in the data (which is also this year or last year)


James
 

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

Similar Threads


Back
Top