Record Count Different in VBA Versus Access [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have an Excel VBA workbook that generates a SQL statement in the form of a string. I pass this SQL into a recordset object and use the CopyFromRecordSet function to dump out the data into an Excel worksheet.
The above method gives me 67 records. If I take the exact SQL generated in VBA and paste into a new query within Access it provides 400 records.
SQL is the following:
SELECT tbJob.jobID,
tbTasks.tskName,
tbTaskCat.catName,
tbTasks.tskActivity,
tbJob.JobDueDate,
tbJob.jobCompletedDate,
tbJob.jobCreatedOn,
tbJobStatus.statusDes,
tbStaff.staffForename & ' ' & tbStaff.staffSurname AS Assignee
FROM tbJobStatus
INNER JOIN (tbStaff
INNER JOIN (tbTaskCat
INNER JOIN (tbTasks
INNER JOIN tbJob
ON tbTasks.tskID = tbJob.jobTaskID)
ON tbTaskCat.catID = tbTasks.tskCatID)
ON tbStaff.staffID = tbJob.jobAssignedToID)
ON tbJobStatus.statusID = tbJob.jobStatusID
WHERE tbJob.jobStatusID = 4
AND tbJobStatus.statusDes <> 'Deleted'
ORDER BY tbJob.jobID;
I am struggling to explain why the difference occurs.
Any help would be appreciated. I have searched around the web but couldn't find a solution, if you know of one please post the link.
Thanks in advance.
Stuart

Related

How to do join using select [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
This post was edited and submitted for review 2 days ago.
Improve this question
SQL Newbie here ...
Service_plan table has a record per customer with PKEY service_plan_id
SERVICE_PLAN_ID table keeps track of version changes with same PKEY
When I run this query [other selects omitted for brevity] in Oracle 10.2.0 iSQL command line, I get an error:
select S1.service_plan_id as TN,V1.VERSION_ID as Version
from Service_plan S1
inner join
(select distinct service_plan_id, max(VERSION_ID)
from SERVICE_PLAN_VERSION
where service_ID='COLL'
group by service_plan_id) as V1
on V1.SERVICE_PLAN_ID = S1.SERVICE_PLAN_ID
where S1.SERVICE_ID='COLL';
Error: missing key word on the "group by service_plan_id) as V1" line - it points to the "as" as the problem.
Any thoughts? Thx
Tried the standalone select and it works fine

Access SQL Syntax error - Unable to find the error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 days ago.
Improve this question
SELECT AgentData.AgentLoginID,AgentData.KPIName,Minimum.Indicator,Minimum.PMonth,Minimum.PYear,Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue,
Round(IIf([Minimum].[Indicator]='P',(IIf([Goal]=0,Null,[GoalValue]/[Goal]),IIf(([Minimum].[Indicator]='N' And ([Minimum].[Min]=0 Or [Minimum].[Min]=(format(0,"Percent")),Null,([Minimum].[Min]-[GoalValue]/[Minimum].[Min]),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
I have been trying to execute this code in access, but no success, i keep getting a syntax error, missing operator in expression, but unable to figure out what the issue is, so wondering if anyone could help, i get an error with the SQL statement marked in bold
SELECT AgentData.AgentLoginID, AgentData.KPIName, Minimum.Indicator, Minimum.PMonth, Minimum.PYear, Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue, Round(IIf([Minimum].[Indicator]='P',IIf([Goal]=0,Null,[GoalValue]/[Goal]),
IIf(([Minimum].[Indicator]='N' And [Minimum].[Min]=0),Null,([Minimum].[Min]-[GoalValue])/[Minimum].[Min])),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product
FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
The above query runs perfectly fine, but i get a snytax errors when i add the OR operator for Minimum.Min as i want it to exectue in two scenarios , one is when Minmum.min is 0 or when minimum.min = 0%

Postgres column doesn't exist error on update [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to run the query below but I am getting an error ERROR: column "test.pdf" does not exist . I dont know why I am getting this error. I search for various links on stackover but none solved my problem like this PostgreSQL query -- column does not exist, Postgres error updating column data. Please help me find the problem.
bill is a type string field in bills table.
update bills
set bill = "test.pdf"
where id=3;
Change the double quotes you have around test.pdf to single quotes.

SQL Server column select query behaving strangely [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
When I do a select * over the table, the column Qty & QtyPending show a value of 6. However explicitly selecting the column names shows different values. Can anyone shed some light as to why this behavior is occurring?
This is a legacy system and database used is SQL Server 2000. The column data types are smallint.
So I have explicitly updated QtyPending to 6 using an Update query. This column now shows correct value.
Also added locstockid to the query, column Qty still shows different values.
Whatever I see in the image provided both the query have different LocStockId which means they can have different values
First :
LocStockId = 152319
Second :
LocStockId = 153219
I think you have mistyped.

SQL Join operation error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to write an SQL code in MS Access 2010 as follows:-
select WOWPerformanceData_tbl.Style,
WOWPerformanceData_tbl.FY,
WOWPerformanceData_tbl.Month,
PrintPromotions.[Type of Offer],
PrintPromotions.Start,
PrintPromotions.End
from WOWPerformanceData_tbl
right join PrintPromtions
on WOWPerformanceData_tbl.Style=PrintPromotions.Style
where (WOWPerformanceData_tbl.Style=[Enter Style nr:]);
Upon running the code, Access returns an error in the join operation pointing to the fourth line and selects PrintPromotions
Any feedback will be appreciated..
Thank you.
Should that be PrintPromotions and not PrintPromtions ?
This is fine as the where clause is an evaluation on the entire set.
SELECT WOWPerformanceData_tbl.Style,
WOWPerformanceData_tbl.FY,
WOWPerformanceData_tbl.Month,
PrintPromotions.[Type of Offer],
PrintPromotions.Start,
PrintPromotions.End
from WOWPerformanceData_tbl
LEFT join PrintPromtions
on WOWPerformanceData_tbl.Style=PrintPromotions.Style
where (WOWPerformanceData_tbl.Style=[Enter Style nr:]);
This would exclude records from printPromotions that were not in wowPerformanceData_tbl, which negates the right join.:
SELECT WOWPerformanceData_tbl.Style,
WOWPerformanceData_tbl.FY,
WOWPerformanceData_tbl.Month,
PrintPromotions.[Type of Offer],
PrintPromotions.Start,
PrintPromotions.End
from WOWPerformanceData_tbl
right join PrintPromtions
on WOWPerformanceData_tbl.Style=PrintPromotions.Style
where (WOWPerformanceData_tbl.Style=[Enter Style nr:]);
This is how you would do it to keep all records from PrintPromotions and those that matched in wowperofrmanceData_tbl.
SELECT WOWPerformanceData_tbl.Style,
WOWPerformanceData_tbl.FY,
WOWPerformanceData_tbl.Month,
PrintPromotions.[Type of Offer],
PrintPromotions.Start,
PrintPromotions.End
from WOWPerformanceData_tbl
right join PrintPromtions
on WOWPerformanceData_tbl.Style=PrintPromotions.Style
AND (WOWPerformanceData_tbl.Style=[Enter Style nr:]);