473,807 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query too Complex

4 New Member
Hi everyone!

I have two tables in my database, named 'n' and 'o' ... n for new and o for old. I have to compare the two tables to c if any value has been changed in any cell for a given cell Id which is the primary key. The fields I'm comparing are more than hundred. Also the values are in number but I'm showing them both concatinated in the result sheet to know which value has been replaced by which so for this I have also used cstr function. Though the query works when I use lesser fields but for all the fields it say's query too complex. I'm pasting the smaller query. Can someone plz tell me if I can make my query more efficient and easy too so the code is less and I can compare all the fields too. I using Acess as database.

Expand|Select|Wrap|Line Numbers
  1. SELECT o.CI AS CI, cstr(o.TCH)+' - '+cstr(n.TCH) AS TCH, cstr(o.NCC)+' - '+cstr(n.NCC) AS NCC, cstr(o.BCC)+' - '+cstr(n.BCC) AS BCC, cstr(o.BCCH)+' - '+cstr(n.BCCH) AS BCCH, cstr(o.CBA)+' - '+cstr(n.CBA) AS CBA, cstr(o.CBQ)+' - '+cstr(n.CBA) AS CBQ, cstr(o.MS_TXPWR_MAX_CCH)+' - '+cstr(n.MS_TXPWR_MAX_CCH) AS MS_TXPWR_MAX_CCH, cstr( o.[Static TRX Power class])+' - '+cstr(n.[Static TRX Power class]) AS [Static TRX Power class], cstr(o.RXLEV_ACCESS_MIN)+' - '+cstr(n.RXLEV_ACCESS_MIN) AS RXLEV_ACCESS_MIN, cstr(o.[RACH Min Access Level])+' - '+cstr(n.[RACH Min Access Level]) AS [RACH Min Access Level], cstr(o.[RACH Busy Threshold])+' - '+cstr(n.[RACH Busy Threshold]) AS [RACH Busy Threshold], cstr( o.CELL_RESELECT_HYSTERESIS)+' - '+cstr(n.CELL_RESELECT_HYSTERESIS) AS CELL_RESELECT_HYSTERESIS, cstr(o.[Cell Reselect Parameters Indication(PI)])+' - '+cstr(n.[Cell Reselect Parameters Indication(PI)]) AS [Cell Reselect Parameters Indication(PI)]
  2. FROM o, n
  3. WHERE o.CI=n.CI And (o.BCC<>n.BCC
  4. or  o.MS_TXPWR_MAX_CCH<>n.MS_TXPWR_MAX_CCH Or o.CBA<>n.CBA Or o.CBQ<>n.CBQ Or o.BCCH<>n.BCCH Or o.NCC<>n.NCC Or o.TCH<>n.TCH Or o.[Static TRX Power class]<>n.[Static TRX Power class] Or o.[DL DTX]<>n.[DL DTX] Or o.[Cell Extension Type]<>n.[Cell Extension Type] Or o.[Direct retry]<>n.[Direct retry] Or o.[Allow Reassign]<>n.[Allow Reassign] Or o.[Half rate supported]<>n.[Half rate supported] Or o.[Cell type]<>n.[Cell type] Or o.[Layer of the cell]<>n.[Layer of the cell] Or o.[Cell priority]<>n.[Cell priority] Or o.[Min DL level on candidate cell]<>n.[Min DL level on candidate cell] Or o.[PBGT HO allowed]<>n.[PBGT HO allowed] Or o.[Load HO allowed]<>n.[Load HO allowed] Or o.[Intra-cell HO allowed]<>n.[Intra-cell HO allowed] Or o.[SD HO allowed]<>n.[SD HO allowed] Or o.[PBGT HO Thrsh]<>n.[PBGT HO Thrsh] Or o.RXLEV_ACCESS_MIN<>n.RXLEV_ACCESS_MIN Or o.[RACH Min Access Level]<>n.[RACH Min Access Level] Or o.[RACH Busy Threshold]<>n.[RACH Busy Threshold] Or o.CELL_RESELECT_HYSTERESIS<>n.CELL_RESELECT_HYSTERESIS Or o.[Cell Reselect Parameters Indication(PI)]<>n.[Cell Reselect Parameters Indication(PI)] );
Jul 3 '07 #1
8 2453
NeoPa
32,579 Recognized Expert Moderator MVP
I would certainly recommend that the FROM clause is changed to use an INNER JOIN.
Otherwise, the layout of the SQL is not such as to make it practical to read.
Jul 3 '07 #2
msabbasi
4 New Member
I would certainly recommend that the FROM clause is changed to use an INNER JOIN.
Otherwise, the layout of the SQL is not such as to make it practical to read.
Can u plz tell me how n how it will help. The two tables are identical represent data of 2 diff days. I need to point out of the changes wherever they might have occurred.
Jul 3 '07 #3
NeoPa
32,579 Recognized Expert Moderator MVP
I can't tell you how to precisely as I don't know the MetaData for your tables. Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; Autonumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Assuming that the primary key of each table is a field called [CellID], it would be like :
Expand|Select|Wrap|Line Numbers
  1. FROM o INNER JOIN n
  2.   ON o.CellID=n.CellID
PS Please don't use text-speak when asking for help in the forums (FAQ - How to Ask a Question). It's hard enough to understand the questions as it is (missing most of the relevant information), without the extra complication of translating into simple English.
Jul 3 '07 #4
msabbasi
4 New Member
Thank you so much for replying. I know how inner join works.
The MetaData for my tables is:

Expand|Select|Wrap|Line Numbers
  1. Table Name=n
  2. Field;Type;Index/info
  3. CI;Numeric;PK
  4. [TCH Flow Control Allowed];Numeric
  5. [Frequency Band of Reassign];Numeric
  6. [T3109(s)];Numeric
  7. CELL_RESELECT_HYSTERESIS
These are 4 of the fields in my tables o and n which are identical.The rest of almost 100 fields are also numeric.
I've modified your code for inner join a bit to make it compare all the fields in both tables

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM o INNER JOIN n ON o.ci=n.ci And (o.BCC<>n.BCC
  3. Or o.[TCH Flow Control Allowed]<>n.[TCH Flow Control Allowed]
  4. Or o.[Frequency Band of Reassign]<>n.[Frequency Band of Reassign]
  5. Or o.[T3109(s)]<>n.[T3109(s)]



This code works very nicely for the 4 fields here but when I add rest of the 100 similar OR clauses it says 'query too complex".

Secondly I want to identify where the values have changed eg where
o.[T3109(s)]<>n.[T3109(s)]. Instead of showing all the fields of both tables n and o I want to show only 1 column per similar column eg only 1 column with heading [T3109(s)] instead of 2. And i want to show a concatenated value if value has eg " 2 - 3" which shows that 2 from table o has changed to 3 in table n.
Jul 3 '07 #5
NeoPa
32,579 Recognized Expert Moderator MVP
Thank you so much for replying. I know how inner join works.
You certainly seem to. Confused that you asked the question (Post #3).
The MetaData for my tables is:

Expand|Select|Wrap|Line Numbers
  1. Table Name=n
  2. Field;Type;Index/info
  3. CI;Numeric;PK
  4. [TCH Flow Control Allowed];Numeric
  5. [Frequency Band of Reassign];Numeric
  6. [T3109(s)];Numeric
  7. CELL_RESELECT_HYSTERESIS
These are 4 of the fields in my tables o and n which are identical.The rest of almost 100 fields are also numeric.
I've modified your code for inner join a bit to make it compare all the fields in both tables.
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM o INNER JOIN n ON o.ci=n.ci And (o.BCC<>n.BCC
  3. Or o.[TCH Flow Control Allowed]<>n.[TCH Flow Control Allowed]
  4. Or o.[Frequency Band of Reassign]<>n.[Frequency Band of Reassign]
  5. Or o.[T3109(s)]<>n.[T3109(s)]
An impressive job. I had to check in the help file to make sure it was valid, but it certainly is 8) In this case you may be missing a closing parenthesis to match the opener before o.BCC<>... Nevertheless still impressive.
This code works very nicely for the 4 fields here but when I add rest of the 100 similar OR clauses it says 'query too complex".
There are limits to what Jet SQL can handle. We'll get to sneaky ways around this later.
Secondly I want to identify where the values have changed eg where
o.[T3109(s)]<>n.[T3109(s)]. Instead of showing all the fields of both tables n and o I want to show only 1 column per similar column eg only 1 column with heading [T3109(s)] instead of 2. And i want to show a concatenated value if value has eg " 2 - 3" which shows that 2 from table o has changed to 3 in table n.
It's perfectly possible to show the "2 - 3" instead of both fields individually. You simply specify that in the SELECT clause.
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2.        '"' & o.BCC & ' - ' & n.BCC & '"' AS BCCDiff,
  3.        ...
Unfortunately, the number and specifications of the columns in a query is built into the query. You can't select different columns on a record by record basis.
Jul 3 '07 #6
NeoPa
32,579 Recognized Expert Moderator MVP
Now, to get to the part about comparing more fields than Access usually likes, it is possible to define QueryDefs (Saved Access Queries) that create a combination of the fields as a single, large composite field. You would then work with these queries and compare the resultant composite fields from the two queries.
As an illustration :
Expand|Select|Wrap|Line Numbers
  1. Qo =
  2. SELECT *,
  3.        [TCH Flow Control Allowed] & ',' &
  4.        [Frequency Band of Reassign] & ',' &
  5.        [T3109(s)] & ',' &
  6.        CELL_RESELECT_HYSTERESIS AS CompField
  7. FROM o
  8.  
  9. Qn =
  10. SELECT *,
  11.        [TCH Flow Control Allowed] & ',' &
  12.        [Frequency Band of Reassign] & ',' &
  13.        [T3109(s)] & ',' &
  14.        CELL_RESELECT_HYSTERESIS AS CompField
  15. FROM n
This can, of course, be done with subqueries if you prefer. It would probably make for quite a large and complex SQL string though. That was English understatement by the way.
The code to use these queries would be of the form :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Qo INNER JOIN Qn
  3.   ON Qo.CI=Qn.CI And Qo.CompField<>Qn.CompField
If the composite field itself gets too long, then break it down into two or three of them which are individually smaller.
Jul 3 '07 #7
msabbasi
4 New Member
I'm working on doing it as 2 queries and then combining it as you said. I hope it'l work.
But one thing I cant find a solution to is that the comparison code that I posted earlier gives me the rows in which the change has occurred but I also want to know which cells in the rows have been changed. Had I been accessing the dataset from a programming language I know what I'd do. I would have used a for loop with an if statement and display data only in the cells where a change has occured else it would be blank. Can I do this in Access some how?
Jul 4 '07 #8
NeoPa
32,579 Recognized Expert Moderator MVP
...But one thing I cant find a solution to is that the comparison code that I posted earlier gives me the rows in which the change has occurred but I also want to know which cells in the rows have been changed. Had I been accessing the dataset from a programming language I know what I'd do. I would have used a for loop with an if statement and display data only in the cells where a change has occured else it would be blank. Can I do this in Access some how?
I did cover this question in post #6.
However, if you like code it is possible (not straightforward but possible) to build a table of the results that you want by processing through the input query. The table contents could then be displayed in a simple query. Even then the query would have a fixed set of columns in the output. That's what queries do.
Jul 4 '07 #9

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

Similar topics

3
3058
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
8980
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
7887
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
8
5069
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can have a query that will pull a single field from all the tables. In other words i should have 44 fields. when i try to do that same, i get an error message saying "Query is too complex"
2
1837
by: Ben de Vette | last post by:
Hi, I'm using the querybuilder when updating a record in a table (Access). However, I get a "Query is too complex" message. The Primary key is autonumbered. Why is it making such a complex update query string in stead of using the primary key? Thanks in advance,
9
2908
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
2113
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
2672
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-
8
6736
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this cover letter for each applicant, there has to be attached a two page document. How in the world can...
0
2458
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...
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
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
10372
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...
0
10112
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
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...
0
6879
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
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.