473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

arrggg! Query to complex!!!

Fotorat
13 New Member
I did this code converts a date into a value -1 to -12 to be used in crosstab report headers.

The problems arises when I insert the last IIF statement for month -12!!!

up to -11 it runs and works but I get The Expression you entered is to complexwhen I inseert the last iff for -12. Any ideas???

this is what tips it over:

,IIf(DatePart(" m",[EFFDT])=DatePart("m", (DateAdd("m",-12,Now()))),"-12")

this is where it works:

MonthsAgo: IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-1,Now()))),"-1",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-2,Now()))),"-2",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-3,Now()))),"-3",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-4,Now()))),"-4",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-5,Now()))),"-5",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-6,Now()))),"-6",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-7,Now()))),"-7",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-8,Now()))),"-8",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-9,Now()))),"-9",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-10,Now()))),"-10",
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-11,Now()))),"-11")))))))))) )
Oct 26 '06 #1
3 1597
birchw
19 New Member
Try this...

MonthsAgo: IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-1,Now())),"-1"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-2,Now())),"-2"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-3,Now())),"-3"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-4,Now())),"-4"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-5,Now())),"-5"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-6,Now())),"-6"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-7,Now())),"-7"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-8,Now())),"-8"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-9,Now())),"-9"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-10,Now())),"-10"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-11,Now()))),"-11"),
IIf(DatePart("m ",[EFFDT])=DatePart("m", (DateAdd("m",-12,Now()))),"-12")
))))))))))
Oct 26 '06 #2
NeoPa
32,578 Recognized Expert Moderator MVP
It's too complex because all the IIfs are nested.
Do you really want columns labelld "-1" to "-12"?
I would have thought "0" to "-11" (current month back till 11 months ago covers the last year) would be more accurate.
Oct 26 '06 #3
NeoPa
32,578 Recognized Expert Moderator MVP
Try
Expand|Select|Wrap|Line Numbers
  1. MonthsAgo: '-' & (12+Month(Date())-Month([EFFDT])) Mod 12
Oct 26 '06 #4

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

Similar topics

3
6192
by: Chris | last post by:
Hello all- Fairly new to SQL and I need to issue a pretty complex query (complex being a relative term here :) ). To dumb down my example for display purposes, I have two tables in my schema a Customer Table :
3
3055
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going on? I have tested this extensively and can say for certain that installing this hot fix is what has caused the performance problem. I just don't know why or how to fix it. Brian Oster
4
8977
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to various forums where I am forced to sign up before I can read any answers. Interesting note here is that the guy in the office next
3
7881
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works something like this: For a (very) simple table containing three rows like this: row 1: A
9
2905
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user wants to be able to check off anywhere between 1 and all 10 fields in a form and have it return a select query with just the fields that were checked off. There are multiple users, so not all users will be checking off the same fields. Some...
10
2111
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social Security # or on Last Name. I've created two different tables with the following fields in each table: ClientInfo Client# (primary key) First Name Middle Name Last Name
1
2670
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. I wanted to execute a query which is retrieving the records from table1 by checking the condition for a long long string . I'm using where clause and checking the condition as-
1
2822
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area I'm trying to fix includes a form which takes entered data, concatenates it into a VB string to form an SQL query, then launches a report with information from the query. Several tables are linked in the query, but the key ones for this problem...
0
2455
crystal2005
by: crystal2005 | last post by:
Hi, I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following 1. The wine name, grape variety, year, winery, and region 2. The minimum cost of wine in the inventory 3. The number of bottles available at the minimum price 4. The total number of bottles available at any price 5. The total number of unique...
21
13495
wordbrew
by: wordbrew | last post by:
I thought I was done with my database, everything was working great, but after going into the query that my subform is based on and simply changing a field from ascending to descending, then closing that and trying to open my form, I got the "query is too complex" error and then everthing went south. Access closed itself and the file was unrecoverable. Luckily I had saved this file with 2 other backups! I tested again. Everything works fine in...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.