Access Giving Wrong Result Using Sql Query

May 10, 2012

I am using a MS access mdb file to display some record from oracle database using odbc connection.I have a table (linked table) called map_detail in mdb as well as oracle with same table structure.I formed one query in mdb (sql query) select * from map_detail where batch_no="SSO15121".It is always fetching some other result, but when I am changing the query by changing the batch no "SSO15148" it is working fine. I noticed that for cases it working.

View Replies


ADVERTISEMENT

Query Giving No Result

Mar 2, 2008

Hi all,

Would appreciate help on this. I have a query which combines the results of 3 queries. Once the underlying queries each has a result I get a result in my query, but if 1 of the underlying queries has no result I get nothing. (I hope this makes sense).

How can I set my query to show results even if the underlying query doesn't.

thanks in advance.

rgs
Ginny

View 5 Replies View Related

Dcount Giving Wrong Results

Jun 14, 2006

Hi Folks,

I have answered my own question so I thought I would share as I couldn't find the solution in any posts. I confess that I don't understand why my results were wrong, but I managed to get them right. :rolleyes:

When using Dcount in a query, I was getting results which did not match the query results. For instance:

Phase_2: DCount("Project_Phase_ID","tbl_Prj_Details","Project_Phase_ID = 2")
gave an answer of 27 when there were in fact 41 projects in that phase.

Searching the forum I came accross this:

Count() always counts the entire domain.

So, Dcount is not counting the record set of my query but something else. I have 4 tables in the query and no idea what domain my dcount was looking at. I presume the various join types were messing with it somehow. :confused:

To get round this, I stripped out the Dcount expressions and changed the query to a make table. I then used the created table as the basis of a query in which I had my Dcounts. The dcount results now agree with the query recordset. :) :) :)

Any background on the bits I clearly don't understand will be gratefully received. I hope this helps someone else sometime.

Kind regards,

Keith.

View 3 Replies View Related

Sum Time Of Specific Field Giving Wrong Totals

Jun 13, 2013

I'm trying to create a query that will sum the total time of a specific field. It seems to be doing it, however the value is off by by a couple minutes on all my examples.

Table

- BusArrivalTime
- BusDepartTime

Query

In my Query I'm making a new field like this. It correctly figures out the difference.

BusWaitTime: DateDiff("n",[BusArrivalTime],[BusDepartTime])

Report

Next I'm displaying that Query information inside of a Report by putting this in the Text Box on the Report. It correctly displays the time in the Hours/Minutes format.

=[BusWaitTime]60 & Format([BusWaitTime] Mod 60,":00")

Lastly, I'm using another Text Box on the Report to Sum the Grand Total of the Wait Time for all my records. Here is what Im putting in the Control Source

=Sum([BusWaitTime])60 & Format([BusWaitTime] Mod 60,":00")

...and it's summing my records, but the value is off by a few minutes and I cant figure out why.

In my example, I have 3 records with times of 3:14, 1:35, and 3:20. It should be totaling a figure of 8:09 but its coming to 8:14 instead.

View 7 Replies View Related

Query With Multiple Outer Joins Gives Wrong Result

Dec 15, 2007

Hello,

My query references 2 related tables: one for persons (PERS) and one for telephone/fax numbers and email addresses (CONT, for Contacts).
The relevant fields are:

PERS
pers_id (long) ---> primary key
pers_forename (text)
pers_surname (text)

CONT
cont_id (long) ---> primary key
pers_id (long) ---> foreign key
come_id (long) ---> foreign key
cont_number (text)

The foreign key come_id refers to a table for contact methods (COME), either "Phone (Home)", "Phone (Work)", "Mobile", "Fax" or "Email".

Now i want to list all persons with their home phone number and email address, also if they don't have one. It seems to be impossible to get it ...
I will explain what happens. Lets start simple: first list all persons with their home phone number (come_id = 1):
SELECT PERS.pers_forename, PERS.pers_surname, CONT.cont_number AS Phone
FROM PERS LEFT JOIN CONT ON PERS.pers_id = CONT.pers_id
WHERE (((IIf(IsNull([come_id]),1,[come_id]))=1));
This works fine. The IIf expression is necessary since we are dealing with an outer join: not all persons have a home phone number. If we would simply put "WHERE come_id = 1" then the query produces only the persons that have a home phone number.

But now i also want to see the email address (come_id = 5):
SELECT PERS.pers_forename, PERS.pers_surname,
CONT.cont_number AS Phone, CONT_1.cont_number AS Email
FROM CONT AS CONT_1 RIGHT JOIN
(PERS LEFT JOIN CONT ON PERS.pers_id = CONT.pers_id)
ON CONT_1.pers_id = PERS.pers_id
WHERE (((IIf(IsNull([cont].[come_id]),1,[cont].[come_id]))=1)
AND ((IIf(IsNull([cont_1].[come_id]),5,[cont_1].[come_id]))=5));
It seems perfectly logical: i added a second alias CONT_1 for the email address. Since this is also optional we have a second outer join, and the WHERE condition should also use an IIf expression.
The result is not correct though: the resulting recordset shows only the persons that have both a home phone number and an email addres or neither!
I have a lot of experience with SQL and queries, but i know i am not infallible. Nevertheless i am quite convinced that i should get all the persons: those that have a home phone number or an email address, or both or neither ...
I hope that someone of you can explain this.

View 3 Replies View Related

Sum Total Giving Interesting Result?

Oct 10, 2007

Ok baisically im doing a quick db for my company that is organising every file stored within the server and monitoring their last access'd, modified etc... I have a query which collates all the files which can be deleted on a server and file count is something alond the lines of 300K+ however i have also Sum'd the file sizes and instead of giving me some mental file size it has given me this result: 1.29659732507E+11

I mean i am no mathematician.. cant even spell it :S anyways im guessing that the number: 1.29659732507E+11 is actually 1.29659732507 to the power of 11?

Is there anyway i can get access to show the actual number i dnt care how long it is i just want a reliable, definitive result i can show my boss!

Cheers

View 1 Replies View Related

Concatenate Not Giving Needed Result

Nov 29, 2007

After searching through 18 pages of search results I have not found the answer. Would someone please tell me why this expression is not working in my query?

RCStatement: """&[RootCauseStatement]&"""

The result is "&[RootCauseStatement]&"

View 4 Replies View Related

SQL Query Giving Different Results In VBA/Access

Jul 11, 2007

Hi ,

I am using Access Application with Orcale Db as backend and this application is already in production.
The problem is.. USers Complained that the system is slow, this is because there is refresh (requery) for each Insert (When they click submit, that particular record is inserted and then a refresh has to be done to bring only unused member IDs on the User screen), i had used a Sql query using NOT IN , then i realized and now changed it to NOT EXISTS, but with this new query , if i test recordset. EOF , even though the query returns more than 13000 ..records, EOF sets to TRUE and the other part (not supposed to) gets executed. I really cant figure out why, i took the same query put it in query builder in Access and ran it , it gave 13000 records..but in VBA , this recordset is not giving expected results and so..i am totally confused..The part of the Code is shown below.

Code:newquery = " SELECT A.MEMBER_ID, A.MEMBER_NAME, A.ADDRESS_LINE1.................. FROM TABLE A WHERE NOT Exists ( SELECT '' FROM TABLE B where A.MEMBER_ID =B.MEMBER_ID)AND A.MATCH_LEVEL <> 0 ORDER BY A.MATCH_LEVEL DESC"rst1.Open newquery, Cnt, adOpenDynamic, adLockOptimisticIf rst1.EOF = False ThenForm_PHS_ASSIGN.RequeryForm_PHS_ASSIGN_SUB.RequeryElse MsgBox " No records to Process!" End If

EVEn though it should requery , it gives a message No records to process which is wrong. It works with NOT IN.... BUT VERY SLOW, NOT EXISTS IS FAST BUT DOES NOT GIVE ME WHAT I WANT..

Where am i going wrong..help pls!!!!

THANKS VERY MUCH!!

View 6 Replies View Related

SQL Query Syntax Giving Access Problems

Jul 12, 2005

Can someone tell me where I might be going wrong here. The following query works in SQL, but somewhere in the LEFT JOINS area, Access gets a little confused and says I'm missing an operator.

SELECT Tariffs.TariffCPUCID, Tariffs.TariffID, AdviceLetters.ALCPUCID, Tariffs.ALID, Tariffs.ScheduleID, Schedules.SheetTitle, AdviceLetters.[Filing Date], Tariffs.[C&E], SheetsCancelling.CancellingID, SheetsCancelling.CancellingCPUCID
FROM Tariffs LEFT JOIN Schedules ON Tariffs.ScheduleID = Schedules.ScheduleID LEFT JOIN AdviceLetters ON Tariffs.ALID = AdviceLetters.ALID LEFT JOIN SheetsCancelling ON SheetsCancelling.TariffID = Tariffs.TariffID
WHERE Tariffs.Type="E"
ORDER BY Tariffs.TariffCPUCID DESC;

View 5 Replies View Related

Queries :: Conditional Query To Post Result In Field And Filter Result Records?

Mar 5, 2014

I am working with Access 2010, on vista. What I have is a query made up of two tables, one product the other inventory. (see below) query.jpg

In the product table i have a field called "minimum reorder level". In the inventory table i have two fields one called "number in stock" and "number on order". What i want to happen is "number on order" to be filtered by the result, if the "number in stock", is less than "minimum reorder level", if it is, have the result placed in the "number on order" field. EG. if the "number in stock" = 2 and the "minimum reorder level" = 5 then 3 would be placed in the field "number on order" and only the second record from the query would be visible (see below) Query result.jpg The result of this would mean that the field "number on order" would be populated with the result and the and query would also use this to filter the record.

View 1 Replies View Related

General :: Adding Count To Result Of Query Depending On Month And Result

Aug 18, 2013

I want to add a number to my results within a query depending on the month and how many results. For example I have 10 results in my query 3 from January, 5 from March and the rest from April. The 3 from January would be 1,2,3. The five in March would be 1,2,3,4,5 and so on. Is it possible to do?

I'm using access 2003.

View 4 Replies View Related

How To Run An Access Query And Show The Result In Excel?

May 13, 2005

I am writing an Excel VBA code to connect to an Access db and execute an access query. After executing the query, I would like to display the result in the excel spreadsheet.

I was successfully able to make the connection to the access db using the following code:

Set db = OpenDatabase("file name", False, True, "MS Access;PWD=abcd")

However, I do not know what code to use to execute a query named "qrytest" on the Access db and show the result in this Excel file.

Can anyone teach me how to do this please?

P.S. I searched this forum for about 1/2 hour before posting this. Please excuse me if this was addressed anywhere before! Would appreciate a link, if it was.

View 1 Replies View Related

Query Not Giving Me What I Need... Help

Nov 1, 2005

This query is getting complicated for me... I need help please! :(
I need it to give me the data for people between FirstMonth, Year and SecondMonth, Year...
Right now it's giving me only the FirstMonth, Year and SecondMonth, Year...
I think I need a between there somewhere but not sure where to put it...??
Hope this makes sense.
I'm doing the query in Access 2002

Thanks
Sarah




SELECT [FirstName] & ", " & [LastName] AS FullName, TriOct10.FirstName, TriOct10.LastName, TriOct10.Address, TriOct10.City, TriOct10.Prov, TriOct10.PostalCode, TriOct10.VolScreenCode, DatePart("m",[PRCDate]) AS Month2, DatePart("yyyy",[PRCDate])+3 AS PRCDueY2, TriOct10.PRCDate, TriOct10.MemberType, TriOct10.MemberStatus, TriOct10.ExpandName, TriOct10.RegOrgName, TriOct10.RegisteredRole
FROM TriOct10
WHERE (((DatePart("m",[PRCDate]))=[Enter 1st Month]) AND ((DatePart("yyyy",[PRCDate])+3)=[Enter First year])) OR (((DatePart("m",[PRCDate]))=[Enter Last Month]) AND ((DatePart("yyyy",[PRCDate])+3)=[Enter Last Year]) AND ((TriOct10.MemberType)="volunteer") AND ((TriOct10.MemberStatus)="Active" Or (TriOct10.MemberStatus)="probationary") AND ((TriOct10.ExpandName) Like "*" & [What Area?] & "*"))
ORDER BY DatePart("m",[PRCDate]), DatePart("yyyy",[PRCDate])+3;

View 2 Replies View Related

How To Use DUAL Table In MS Access To Add Rows To Query Result

Dec 2, 2011

How to add my own rows to a query in MsAccess ? I would like to do something like this: Select Name from Table 1 where age > 75 Union Select "Joe" from Dual; Expected Result: If Joe is not found in Table 1 ,then it would be added to the result of the query.How can I do it in MsAccess as it does not use " DUAL" table.

View 1 Replies View Related

Sub Query Giving Me Grief....Please Help...! Tx

Apr 20, 2006

Hi all.

I have a sub query that was working until a couple of days ago when it decided to stop.

I have a Table called TblFieldValues which whenever a new value is entered into my relational Db.
Each new Value is given a ValueID and is Dated (full date/time stamp)

My Sub Query ensures that for each FieldID (ie if more than 1) it selects/shows the top most Date....But it is not grabbing all the fields for some reason???

Here is the SQL limiting criteria to a bare minimum (QuoteID)
SELECT Main.FieldID, Main.QuoteID, Main.QuoteTypeID, Main.SubSection, Main.FieldValue, Main.NumberFieldValue, Main.CalcFieldValue, Main.Date, Main.ValueID
FROM TblFieldValue AS Main
WHERE (((Main.QuoteID)=[Forms]![FrmQuote]![QuoteID]) AND ((Main.ValueID) In (SELECT TOP 1 Sub.ValueID FROM TblFieldValue AS Sub WHERE Sub.FieldID=Main.FieldID ORDER BY Sub.Date DESC)));

I had a thought it might be the way the info is put into TblFieldValues, as it is often put in via Code, in fact only when it is put via code is it not showing up as a rule.
So I had a look at the code that inserts it.

strSQL = "INSERT INTO TblFieldValue ([QuoteID], [QuoteTypeID], [SectionID], [FieldID], [FieldValue], [Date], [UpdatedBy]) Values ('" & strQuoteID & "', '" & strQuoteType & "', '" & strQuoteSection & "', '" & strFieldID & "', '" & strValue & "', '" & strDate & "', '" & strUser & "');"

'MsgBox strSQL

DoCmd.RunSQL strSQL

I had Now() in replace of strDate, but tried changing to strDate and diming strDate as Date and then setting strDate = Now() but doesn't really change it in the table.

I am certain it is in this somehow? Any ideas????
Your help will be greatly appreciated...

View 2 Replies View Related

Queries :: If There Is No Result In Query Need To Have Default Result Zero

Oct 12, 2013

I there is no result in query, I need the default result zero in my form field. I only use query wizard to create queries.

View 5 Replies View Related

Query Giving Too Many Results (duplicates)

Mar 27, 2006

I have a query that selects from a table base on 3 entries (Name, BeginDate and EndDate) and should show me 12 other columns and their entries... I have 9 entries for a particular Name, but when i run the query i get 15 results. Some are duplicated but others are not and I don't know where to begin narrrowing it down. Any ideas where to start?

View 2 Replies View Related

Giving A Query Parameter Using A Text Box

Nov 8, 2004

Hello everybody!

I 've created a query that copies the records of a table into the same table, creating new records. (I don't know how this is called in english, sorry). For example if have a table with 2 records when the query is run I have 4 records with duplicates. The fields of each record I want to remain the same except for one, called code. For example:
this is the table before the query is run:

surname name code
tracy john 1
spencer bud 1

and this is the table after the query is run:

surname name code
tracy john 1
spencer bud 1
tracy john 2
spencer bud 2

the code is also in an another table and is included in a textbox in my main form. Everything works fine when I run the query but I must type a parameter (code) to create the duplicated table. How can I pass the parameter to the query "automatically", using the textbox value?
Thanx in advance

View 3 Replies View Related

Query Giving ID Instead Of Text In Report

Oct 27, 2014

SELECT Count([Unsafe Act ].[Tag]) AS [CountOfTag], [Unsafe Act ].[Audit], [qryTag].[Tag]
FROM [Unsafe Act ] LEFT JOIN [qryTag] ON [Unsafe Act ].[Tag] = [qryTag].ID
WHERE ((([Unsafe Act ].Date) Between [Forms]![frmSafetyReportOut]![startDate] And [Forms]![frmSafetyReportOut]![endDate]))
GROUP BY [Unsafe Act ].[Audit], [qryTag].[Tag]
HAVING ((([Unsafe Act ].[Audit])=[Forms]![frmSafetyReportOut]![cboConditionAct]))
ORDER BY Count([Unsafe Act ].[Source Of Tag]) DESC;

I am trying to run this query and query works fine however I am trying to run a chart on the report which shows ID's of Tag instead of txt of Tag.

View 2 Replies View Related

Queries :: Run Saved Query Object In Access Through VBA And Display Result In Subform

Jun 25, 2014

I have saved query object named qrySearchBill. I wan to call this query through vba and display the result in a subform named subQrySearchBills in datasheet view. Here's how I want it to work:

When the main form loads, I want all unfiltered records to be displayed in the subform initially. The user may then decide to filter based on date range, so he enters startdate and enddate parameter values in their respective textboxes in the main form. Then click search button to run the saved query based on the date range parameter taken from the textboxes.

I have this code so far:

SQL of the saved query object:

Code:
PARAMETERS [StartDate] DateTime, [EndDate] DateTime;
SELECT tblInvoice.BillNo, tblCrdCustomer.CstName, tblCrdCustomer.CstAddress, tblCrdCustomer.Island, tblInvoice.Date, Sum(tblInvoice.[TotalPrice]) AS Amount
FROM tblCrdCustomer INNER JOIN tblInvoice ON tblCrdCustomer.IDNo = tblInvoice.NameID
WHERE tblInvoice.Date Between [StartDate] And [EndDate]
GROUP BY tblInvoice.BillNo, tblCrdCustomer.CstName, tblCrdCustomer.CstAddress, tblCrdCustomer.Island, tblInvoice.Date;

vba code to call the query and its parameter:

Private Sub btnSearchBill_Click()
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset

Set qdf = CurrentDb.QueryDefs("qrySearchBills")

[Code] ...

This code works fine except that when the main form loads, a prompt window appears to ask for the value of dateStart and dateEnd. I don't want it to prompt because it's suppose to get these values from the main form's textboxes (txtStartDate and txtEndDate respectively), plus it should initially display all the unfiltered records.

View 3 Replies View Related

Odd Query Problem Giving Me Grey Hairs.

Mar 10, 2008

I have a query that updates a field on a table with the value in another field. When I run the query from the Access control panel, the query does exactly what it should do, 100% perfect. When I call the query using DoCmd.OpenQuery in VBA in an OnClick function on a form, it does not work properly, only appending certain amounts of information, leaving some fields blank.Can anyone shed some light on this.the SQL for the query is:UPDATE tblHolding SET tblHolding.CostGRV = [tblHolding]![OrderCost]WHERE ((([tblHolding].[Item Code])=[tblHolding]![Item Code]));It populates another field in the same record in the same table as itself.tblHolding is populated by a Subform on the Form that has the button that calls this query when clicked.Hope I am making sense.

View 3 Replies View Related

Queries :: Unique Query Is Giving Duplicates

Aug 4, 2015

I have a unique query which lists all the films that we are screening over the next 3 months. I have added a COUNT field so that I can see how many of each films we are screening.

The problem is that i get duplicates of some films - and this may be because we may hold several copies of some films. I have attached two images which might explain this better!

What I could do with is knowing how to make it so that i get a list of films booked and how many of each, regardless of which copy of the film is used.

The SQL is:

Code:
SELECT DISTINCTROW dbo_Films.[film name], Count(dbo_Films.[film name]) AS [CountOffilm name]
FROM ((dbo_Films INNER JOIN dbo_filmCopies ON dbo_Films.ID = dbo_filmCopies.tblFilms_ID) INNER JOIN dbo_EventsFlicks ON dbo_filmCopies.ID = dbo_EventsFlicks.filmCopyID) INNER JOIN dbo_Venues ON dbo_EventsFlicks.venueID = dbo_Venues.ID
WHERE (((dbo_EventsFlicks.datefield)>=#8/1/2015# And (dbo_EventsFlicks.datefield)<#1/1/2016#))
GROUP BY dbo_Films.[film name], dbo_Venues.southhub, dbo_Venues.northhub, dbo_Films.Specilaised
ORDER BY dbo_Films.[film name];

View 4 Replies View Related

Update Query Giving Me A Runtime Error 3061

Oct 27, 2005

Hi there....Im busy tonight trying to get a couple of things working correctly.

I have an UPDATE string that I am trying to get working but I am getting a runtime error 3061 saying 'To few parameters Expected 1'

I have tried the same query using the query builder and it works ok...when I try it in VBA it doesn't work.

This is my code


Dim SQLUpdate As String
Dim SQLWhere As String
Dim strComplete As String


SQLUpdate = " UPDATE tblPersonalInformation SET tblPersonalInformation.DateModified = Now() "
SQLWhere = " WHERE tblPersonalInformation.PersonalID = [Forms]![frmMain]![txtCandidateNumberReadOnly]"



strComplete = SQLUpdate & SQLWhere
Debug.Print strComplete


CurrentDb.Execute strComplete
End Sub


Can anyone see what I am missing or I am doing wrong?


Thanks evryone for your help.

View 5 Replies View Related

Wrong Access Icon

Dec 10, 2006

hi all,
this morning i installed the ms access 2000 runtime and then i uninstalled it.
After that i had some problems and there was no other choice than uninstall and install the office 97.
Now for some reason the access 97 works BUT the mdb files have a notepad icon instead the access 97 icon.
however, if i see the icon's properties under OPEN WITH the icon is the correct one.

can u hlp me?
thx in advance, 4 your time, max.

View 2 Replies View Related

Access / Excel VBA - ActiveCell Refers To Wrong Workbook

Jul 22, 2014

I have a procedure in Access that exports three reports to Excel, combines them in a single workbook, and then applies Excel formatting to some of the sheets. This procedure works the first time, but if I run it again it fails. In particular, I notice that things like "ActiveCell" and "Selection" will continue to refer to the previous workbook (dim xlWkb), even though I've activated the current worksheet/workbook.

Code:
Dim xlApp As Excel.Application
Dim xlWkb As Excel.Workbook
Dim xlBwkb As Excel.Workbook

[code]....

'BillingTemp, etc. are defined earlier in the procedure. I essentially am exporting Access reports to temporary Excel files, and then opening the files and putting them in a single workbook.

Set xlBwkb = xlApp.Workbooks.Open(BillingTemp)
xlBwkb.Sheets(1).Copy After:=xlWkb.Sheets(1)
xlBwkb.Close False
Set xlBwkb = xlApp.Workbooks.Open(PrismTemp)
xlBwkb.Sheets(1).Copy After:=xlWkb.Sheets(2)
xlBwkb.Close False

[code]....

'After combining the exported reports into one Excel workbook, I apply some formatting to some of the sheets.

Dim i As Integer
Dim rng As Range
Dim b As Range
Dim lastRowB As Integer
Dim Indication As String
Dim ws As Worksheet

[code]....

View 4 Replies View Related

What Is Wrong With This Query?

Jan 15, 2007

SELECT s.weekth, s.contracttype, sum(case when s.[contract status]='advance complete' then price end)/sum([purchaing price])

from submissionandpd as s

THX

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved