473,394 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is there any alternative way to write this query because it causes ms access to stop

I have my query like this:
Expand|Select|Wrap|Line Numbers
  1. Select p2.SiebelProdOffID as OfferId
  2.    , p2.ProdOffName as RootOffering
  3.    ,p3.SiebelProdOffID as L2OfferId
  4.    ,p1.Participant2Name as L2OfferComponent
  5.    ,(Cstr(p4.End2Min)+'..'+Cstr(p4.End2Max)) 
  6.       as L2Cardinality
  7.    , Null as L3OfferId 
  8.    ,Null as L3OfferComponent
  9.    , Null as L3Cardinality
  10. from ((ProdOffToProdOffAssoc p1
  11.    right join ProdOff p2 
  12.       on (p1.Participant1Name=p2.ProdOffName 
  13.          and p1.AssocTypeName='Aggregation'))
  14.    left join ProdOff as p3 
  15.       on p1.Participant2Name=p3.ProdOffName)
It causes ms access to stop the application.

please omit the attribut of alias p4.

The query looks like this:
Expand|Select|Wrap|Line Numbers
  1. Select p2.SiebelProdOffID as OfferId
  2.    , p2.ProdOffName as RootOffering
  3.    ,p3.SiebelProdOffID as L2OfferId
  4.    ,p1.Participant2Name as L2OfferComponent
  5.    , Null as L3OfferId 
  6.    ,Null as L3OfferComponent
  7.    , Null as L3Cardinality 
  8. from (((ProdOffToProdOffAssoc p1
  9.    right join ProdOff p2 
  10.       on (p1.Participant1Name=p2.ProdOffName 
  11.          and p1.AssocTypeName='Aggregation'))
  12.    left join ProdOff as p3 
  13.       on p1.Participant2Name=p3.ProdOffName)
Jun 27 '16 #1
9 1051
zmbd
5,501 Expert Mod 4TB
+ When you say, "... ms access to stop the application. ..."
Do you mean that Access shuts down without any warning or are you intending some other "stops" as in it will not run the intended code or query

+ There are multiple errors in the formatting of the posted SQL; however, I suspect that these are typos.

To get around this, please open your query in "design view, "switch to "SQL View" (various methods, easiest is the bottom right hand corner in Design View, three icons, one is "SQL"; the second easiest is to right-click in the table section of the query editor and select {SQL View} from the shortcut menu

Select the SQL as presented and copy and paste that to the thread. PLEASE select the posted SQL and format it using the [CODE/] tool.

+-+ Off hand:
Block2 Line8 "ProdOffToProdOffAssoc p1", should this be "[ProdOffToProdOffAssoc p1]" if you really have a space there or do you intend "[ProdOffToProdOffAssoc]![p1]" as in a table-field relationship?

Same thing with Block2 Line9 "ProdOff p2"

etc...
Jun 27 '16 #2
NeoPa
32,556 Expert Mod 16PB
ZMBD:
should this be "[ProdOffToProdOffAssoc p1]"
No. I suspect this means :
Expand|Select|Wrap|Line Numbers
  1. [ProdOffToProdOffAssoc] AS [p1]
These are both valid ways to write the same thing, though I prefer always to be explicit to avoid any possibility of confusion.
Jun 27 '16 #3
zmbd
5,501 Expert Mod 4TB
Personally, I don't like the implicit options, especially when mixed in with explicit calls... I wonder if that isn't part of the issue - along the lines of if one is going to square-bracket ([]) part of the SQL one should do so for the entire SQL?
Jun 27 '16 #4
NeoPa
32,556 Expert Mod 16PB
In answer to the original question I'd say this looks like the tables are linked by a name field. With large numbers of records this can cause Access to stop responding for long periods of time and appear to have stopped.

First understand that Access typically stops responding in many situations where queries are run. This is actually not an indication of a real problem, but simply of a delay while it works on getting results.

Second, linking tables on a non indexed field is likely to be many times slower than using an index. A long text field in an index is likely to be many times slower than a numeric field or a text one of short length. A Long Integer will take up eight bytes of space. A similar length string field is fine.

When writing queries it's probably a good idea to use either LEFT or RIGHT JOINs, but not both. It will still work as well, but be more difficult to understand.

Seeing your SQL I suspect you may have need of a read of Database Normalisation and Table Structures.
ZMBD:
Personally, I don't like the implicit options, especially when mixed in with explicit calls
I agree, as is probably clear from my comment (Cross-posted).
Jun 27 '16 #5
when i try to run only a part of the query i.e
Expand|Select|Wrap|Line Numbers
  1. SELECT p2.SiebelProdOffID AS OfferId
  2.    , p2.ProdOffName AS RootOffering
  3.    , p3.SiebelProdOffID AS L2OfferId
  4.    , p1.Participant2Name AS L2OfferComponent
  5.    , (Cstr(p4.End2Min)+'..'+Cstr(p4.End2Max)) 
  6.       AS L2Cardinality, Null AS L3OfferId
  7.    , Null AS L3OfferComponent, Null AS L3Cardinality
  8. FROM (ProdOff AS p2 
  9.    left JOIN ProdOffToProdOffAssoc AS p1
  10.       ON p1.AssocTypeName='Aggregation' 
  11.       and p1.Participant1Name=p2.ProdOffName) 
  12.    LEFT JOIN ProdOff AS p3 
  13.       ON p1.Participant2Name=p3.ProdOffName;
I have now used left join as you said NeoPa but it gives me error near
Expand|Select|Wrap|Line Numbers
  1. p1.AssocTypeName='Aggregation'
saying 'Join expression not supported'. I can't use this condition in where because it gives a completely different resultset.
Jun 28 '16 #6
hey i got the solution for this .
"JOIN expression not supported" error was caused by unbracketed JOIN expression comprising string condition.
This has been an issue since Access version 1.
The one work-around i found, it may not work on all scenarios but it fits most of them.

Problem Query:
Expand|Select|Wrap|Line Numbers
  1. SELECT p2.SiebelProdOffID AS OfferId
  2.    , p2.ProdOffName AS RootOffering
  3.    , p3.SiebelProdOffID AS L2OfferId
  4.    , p1.Participant2Name AS L2OfferComponent
  5.    , (Cstr(p4.End2Min)+'..'+Cstr(p4.End2Max))
  6.        AS L2Cardinality, Null AS L3OfferId
  7.    , Null AS L3OfferComponent, Null AS L3Cardinality
  8. FROM (ProdOff AS p2 
  9.    left JOIN ProdOffToProdOffAssoc AS p1
  10.      ON p1.AssocTypeName='Aggregation' 
  11.       and p1.Participant1Name=p2.ProdOffName) 
  12.    LEFT JOIN ProdOff AS p3 
  13.       ON p1.Participant2Name=p3.ProdOffName;
Work Around:
Expand|Select|Wrap|Line Numbers
  1. SELECT p2.SiebelProdOffID AS OfferId
  2.    , p2.ProdOffName AS RootOffering
  3.    , p3.SiebelProdOffID AS L2OfferId
  4.    , p1.Participant2Name AS L2OfferComponent
  5.    , (Cstr(p4.End2Min)+'..'+Cstr(p4.End2Max)) 
  6.       AS L2Cardinality, Null AS L3OfferId
  7.    , Null AS L3OfferComponent, Null AS L3Cardinality
  8. FROM (ProdOff AS p2 
  9.    left JOIN ProdOffToProdOffAssoc AS p1  
  10.       ON p1.AssocTypeName & p1.Participant1Name
  11.          ='Aggregation' & p2.ProdOffName
  12.    LEFT JOIN ProdOff AS p3 
  13.       ON p1.Participant2Name=p3.ProdOffName;
Jun 28 '16 #7
NeoPa
32,556 Expert Mod 16PB
Why are you using a literal value in your JOIN?

The solution is a kludge. This should be in the WHERE clause instead to make sense.

Linking on a calculation (X & Y) is very inefficient as it precludes the use of indexes. Basically a situation that should be avoided.
Jul 2 '16 #8
zmbd
5,501 Expert Mod 4TB
Neopa,

Could this then be re-written as a subquery using LEFT JOINS so that
Expand|Select|Wrap|Line Numbers
  1. <note this is "air code">
  2. (SELECT [...needed fields...]
  3. FROM ProdOffToProdOffAssoc 
  4. WHERE [AssocTypeName]='Aggregation') AS P2
Then LEFT JOIN p1.Participant1Name=p2.ProdOffName

I've never ran in to OP's situation using the literal value on a join, I've always joined against a table or (sub)Query.
Jul 3 '16 #9
NeoPa
32,556 Expert Mod 16PB
It could, but there's no reason I see to complicate it that far. A WHERE clause could be used.
Jul 3 '16 #10

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

Similar topics

8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
5
by: meyvn77 | last post by:
I wrote a bunch of SQL statement in SQL SERVER and now im trying to do the same thing in access. OMG what a pain that Access can't handle updates or CAST() the way SQL server can. OK I thought I...
0
by: Andrew W | last post by:
Hi All, I have a query that summarizes some data from a table as an average, max and standard deviation. This query works fine. It returns a value not a null. When I use a select query to...
0
by: abhishekjethwani | last post by:
How to write a query to access tree structure form multi table. I m having five tables from them first table give me a data which act as the parameter for query for the second table and the two...
5
by: Jim | last post by:
I'm a vb.net newbie. I have an query that is entirely within an Access database. It's a simple update query - "usp_Append_tbl_RefNos". It works in Access, How can I run that query from a vb...
1
by: rune | last post by:
Hi I'm trying to convert an SQL Query from Access to SQL Server. The Access Query goes like this: SELECT Format(EntryDate, 'ddd mm dd') AS FROM JournalEntries This query returns the name...
9
by: anthony | last post by:
In Access 2007, why does a query field designed as Term: ! ! return 00:00:00 when cboTerm actually contains 08SP. This works as expected in Access 2003?
0
by: csin | last post by:
I have an Access DB backend for the application I am running, I want to use the built in ability in Access to remove duplicate entries... Say I have table1 with fields field1 field2 and field3,...
1
by: Kris RIchard | last post by:
I am trying to write a query in Access based on the following: Table 1 has one item with a serial number (primary key). Each item has Table2_lot1, Table2_lot2, Table2_lot3 etc. Table 2 has one...
5
by: vishal prada | last post by:
ResultSet res = st.executeQuery("select * from regist where Password='"+User_Password+"'"); if(res.next()==true) { ps = con.prepareStatement("update regist set Password=?,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.