I m trying to run a sql in access 2007 which gives the error
"you tried to execute a query that does not include the specified expression 'round(volumePass/Volume*100,2)' as part of an aggregate function".
Whereas i have mentioned it in the sql statement
group by round(volumePass/Volume*100,2)
SELECT s.[sub process name], Round(Avg(s.[TollGate FTEs]),2) AS TollGateFTEs,
Sum(w.volume) AS Volume,
Sum(Switch(w.TAT='Pass',w.Volume,w.TAT='Fail',0)) AS VolumePass,
Sum(IIf(w.[combined accuracy]='PASS',1,0)) AS AccuracyPass,
Sum(IIf(w.[combined accuracy]='',0,1)) AS TotalAccuracy,
Round((VolumePass/Volume)*100,2) AS TATPercentage,
Round((AccuracyPass/TotalAccuracy)*100,2) AS AccuracyPercentage,
Format(w.[reporting month],'mmm-yy') AS [Rep Month] FROM Work_Log1 AS w,
[sub process] AS s WHERE w.[sub process] In (SELECT s.[sub_process_id] FROM
[Sub Process] s,
[process mapping] m where m.[process name] like 'Accounting Control%'
and s.[mapped to process id] = m.[mapping id]) And w.[sub process]=[s].[sub_process_id]
AND (w.[Activity_start_date] Between #06/01/2012# And #06/15/2012#)
AND ([w].[sla applicable]=1 Or 0 Or '') and
(w.[status] Like 'Complete%') group BY Format(w.[reporting month],'mmm-yy'),
s.[sub process name], (Round((VolumePass/Volume)*100,2));
Where is that it is not able to pick up correctly.
giving the alias "TATPercentage" still not works and gives the same error.
This query works well in access query designer but cannot be run with sql inside vba.
Update:
Got it to run using the dao engine in vba.. no luck with adodb engine
Round((VolumePass/Volume)*100,2) AS TATPercentage
^^^^^^^^^^ ^^^^^^
round() is not an aggregate function. You'll have to group on those fields as well (volumepass and volume), and you'll run into the same error with your next two lines with accuracypass, acuracytotal, reporting month, etc...
Related
Can somebody tell me what i have done wrong in my Parameter query as it does not work?
Basically my intention is to create a search result and display it using DataGridView.
These errors appear when I click 'Execute Query' on query builder window.
Below is the SQL Statement
SELECT Products.[Product Name], Products.[Product code], [Brands For Sales].[Brand Name], [Main Group].[Group Name], Category.[Catogory Name], SubCatogory.[SubCatogory Name]
FROM (((((Products INNER JOIN
Category ON Products.[Category-ID] = Category.ID)
INNER JOIN
[Brands For Sales] ON Products.[Brand Name] = [Brands For Sales].ID) INNER JOIN
[Main Group] ON Products.[Group-ID] = [Main Group].ID AND Category.[Group-ID] = [Main Group].ID) INNER JOIN
Category Category_1 ON Products.[Category-ID] = Category_1.ID AND [Main Group].ID = Category_1.[Group-ID]) INNER JOIN
SubCatogory ON Products.[SubCategory-ID] = SubCatogory.ID AND Category.ID = SubCatogory.[Catogory-ID] AND Category_1.ID = SubCatogory.[Catogory-ID])
WHERE (Products.[Product Name] LIKE '%' + #Searchbox + '%')
If I remember correctly, Query Builder doesn't support named parameters even for SQL Server, never mind Access. Replace each of your #ParameterName placeholders with ? and you should be good to go.
EDIT:
The only thing that changes when using positional parameters rather than named parameters (other then the fact that you must add them in the same order as they appear in the SQL, which you should do anyway) is that you cannot reuse a parameter. That means that you might have to pass the same value twice. For instance, if you used this SQL with named parameters:
SELECT *
FROM MyTable
WHERE Column1 = #SomeValue
OR Column2 = #SomeValue
and then you passed a single value to a single parameter to be used twice in the SQL code, you would change the SQL to this with positional parameters:
SELECT *
FROM MyTable
WHERE Column1 = ?
OR Column2 = ?
and then your command would have two parameters and you would pass the same value to both of them. That's exactly what everyone already does with Access even if they do name their parameters, because the Jet and ACE OLE DB providers ignore those names and use positions anyway.
I have a ComboBox which takes it's source from a query. One of the query' fields is a number like H-1234=AAA-0382 or HN903=BBB-94522 (Field is ID Symix, Table is DessinSelonProjet_Choix).
In the combobox, I want to display this number, but not the part before the = sign in both cases. I wanted to use a Mid(number, position of = sign). In SQL I researched that the position function is CHARINDEX, but I did not manage to get it working.
Here is the code when showing the whole thing:
SELECT DessinSelonProjet_Choix.[ID Symix], DessinSelonProjet_Choix.[Numéro Document],
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];
Here is what I tried:
SELECT Mid(DessinSelonProjet_Choix.[ID Symix],CHARINDEX('=',
DessinSelonProjet_Choix.[ID Symix]) AS [Location]) AS Expr1,
DessinSelonProjet_Choix.[Numéro Document],
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];
Syntax error (missing operator) in the expression Mid(DessinSelonProjet_Choix.[ID Symix],CHARINDEX('=', DessinSelonProjet_Choix.[ID Symix]) AS [Location]) AS Expr1
SELECT
Mid([ID Symix], INSTR('=', [ID Symix])+1, len([ID Symix])-INSTR('=', [ID Symix])) AS Expr1,
[Numéro Document],
Description,
[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY [ID Symix];
The statement you had was using an alias within a function. Also, you have to use len to get all characters after = in your string.
I don't know ABCDs of MDX. I have this query that was handed over to me by my predecessor and that it is needed only once in a year! That time of the year happens to be now! The query runs and returns the results. However, I am unable to copy the result along with the rows and column names from the SSAS result window.
Googling I found the options of Linked servers, setting query options to save the result as csv etc, using SSIS packages and PowerPivot.
The first two are not possible because of restrictions on the DB. I need to go over a bunch of corporate hurdles to get the necessary permissions.
SSIS packages and Power Pivot - have the same issue. 'BUD' is a named set and it is referenced in the filter below in select statement. Both SSIS (when typed in OLEDB Source) throws error - The dimension [BUD] was not found.
Working with PowerPivot, I executed set create statement separately and then pasted only the code after 'WITH'. The Error was -The dimension [BUD] was not found.
Any help of how to reference the BUD in the select statement for Power Pivot or SSIS? I am using sqlsever2008r2.
This the procedure -
create set [DB1].BUD AS
nonemptycrossjoin(
{[Market].[Markets].&[Europe].children,[Market].[Markets].[Part of World].&[Africa].children},
[Product].[PL].&[CD] : [Product].[PL].&[KZ],
[Plant].[Plant].children
) go
with
member measures.callsCY1 as
/* Lot of measure calutaions here */
select
non empty
{
[Measures].[Qty Sold],
callsCY1,costCY1,MTRLcostCY1,LabourCostCY1,
SCR_C,callsRY1,costRY1,MTRLcostRY1,LabourCostRY1,
callsCY2,costCY2,MTRLcostCY2,LabourCostCY2,
callsRY2,costRY2,MTRLcostRY2,LabourCostRY2,
callsCY3,costCY3,MTRLcostCY3,LabourCostCY3,
callsRY3,costRY3,MTRLcostRY3,LabourCostRY3
}
*
{[Report Period].[Report Periods].[Quarter].&[2013-01-01T00:00:00] : [Report Period].[Report Periods].[Quarter].&[2014-06-01T00:00:00]}
on 0,
non empty
filter(
bud, [Measures].[Qty Sold] <> 0 OR [Measures].[QTY Service Calls] <> 0)
on 1
from [db1]
Does bud need to be seperate? Can't you just use this?
with
set [BUD] AS
nonemptycrossjoin(
{[Market].[Markets].&[Europe].children,[Market].[Markets].[Part of World].&[Africa].children},
[Product].[PL].&[CD] : [Product].[PL].&[KZ],
[Plant].[Plant].children
)
member measures.callsCY1 as
/* Lot of measure calutaions here */
select
non empty
{
[Measures].[Qty Sold],
callsCY1,costCY1,MTRLcostCY1,LabourCostCY1,
SCR_C,callsRY1,costRY1,MTRLcostRY1,LabourCostRY1,
callsCY2,costCY2,MTRLcostCY2,LabourCostCY2,
callsRY2,costRY2,MTRLcostRY2,LabourCostRY2,
callsCY3,costCY3,MTRLcostCY3,LabourCostCY3,
callsRY3,costRY3,MTRLcostRY3,LabourCostRY3
}
*
{[Report Period].[Report Periods].[Quarter].&[2013-01-01T00:00:00] : [Report Period].[Report Periods].[Quarter].&[2014-06-01T00:00:00]}
on 0,
non empty
filter(
bud, [Measures].[Qty Sold] <> 0 OR [Measures].[QTY Service Calls] <> 0)
on 1
from [db1]
SELECT
e.DESCRIPTION AS [EQUIPMENT TYPE],
Count(e.EQNAME) AS QUANTITY,
Sum(IIf(e.CONDITION = 'Functional', 1, 0)) AS WORKING,
Sum(IIf(e.CONDITION = 'Non-Functional', 1, 0)) AS [NON-WORKING]
FROM EQUIPMENTS AS e
GROUP BY e.DESCRIPTION;
I tried using this query in VB.net TableAdapter Query Configuration wizard and an error occurs.
Error in list of function arguments: '=' not recognized.
Unable to parse query text
Error in GROUP BY clause.
This Query works well in MS Access, what's the difference from it in VB.Net?
I already have a solution to this problem. I just used this query as a stored query in MS-Access then used in my VB.Net Code. Thank you guys.
i'm having an issue comparing a date in an access database. basically i'm parsing out a date from a text field, then trying to compare that date to another to only pull newer/older records.
so far i have everything working, but when i try to add the expression to the where clause, it's acting like it's not a date value.
here's the full SQL:
SELECT
Switch(Isdate(TRIM(LEFT(bc_testingtickets.notes, Instr(bc_testingtickets.notes, ' ')))) = false, 'NOT ASSIGNED!!!') AS [Assigned Status],
TRIM(LEFT(bc_testingtickets.notes, Instr(bc_testingtickets.notes, ' '))) AS [Last Updated Date],
bc_testingtickets.notes AS [Work Diary],
bc_testingtickets.ticket_id,
clients.client_code,
bc_profilemain.SYSTEM,
list_picklists.TEXT,
list_picklists_1.TEXT,
list_picklists_2.TEXT,
list_picklists_3.TEXT,
bc_testingtickets.createdate,
bc_testingtickets.completedate,
Datevalue(TRIM(LEFT([bc_TestingTickets].[notes], Instr([bc_TestingTickets].[notes], ' ')))) AS datetest
FROM list_picklists AS list_picklists_3
RIGHT JOIN (list_picklists AS list_picklists_2
RIGHT JOIN (list_picklists AS list_picklists_1
RIGHT JOIN (bc_profilemain
RIGHT JOIN (((bc_testingtickets
LEFT JOIN clients
ON
bc_testingtickets.broker = clients.client_id)
LEFT JOIN list_picklists
ON
bc_testingtickets.status = list_picklists.id)
LEFT JOIN bc_profile2ticketmapping
ON bc_testingtickets.ticket_id =
bc_profile2ticketmapping.ticket_id)
ON bc_profilemain.id =
bc_profile2ticketmapping.profile_id)
ON list_picklists_1.id = bc_testingtickets.purpose)
ON list_picklists_2.id = bc_profilemain.destination)
ON list_picklists_3.id = bc_profilemain.security_type
WHERE ( ( ( list_picklists.TEXT ) <> 'Passed'
AND ( list_picklists.TEXT ) <> 'Failed'
AND ( list_picklists.TEXT ) <> 'Rejected' )
AND ( ( bc_testingtickets.ticket_id ) <> 4386 ) )
GROUP BY bc_testingtickets.notes,
bc_testingtickets.ticket_id,
clients.client_code,
bc_profilemain.SYSTEM,
list_picklists.TEXT,
list_picklists_1.TEXT,
list_picklists_2.TEXT,
list_picklists_3.TEXT,
bc_testingtickets.createdate,
bc_testingtickets.completedate,
DateValue(TRIM(LEFT([bc_TestingTickets].[notes], Instr([bc_TestingTickets].[notes], ' '))))
ORDER BY Datevalue(TRIM(LEFT([bc_TestingTickets].[notes], Instr([bc_TestingTickets].[notes], ' '))));
the value i'm trying to compare against a various date is this:
DateValue(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' '))))
if i add a section to the where clause like below, i get the Data Type Mismatch error:
WHERE DateValue(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' ')))) > #4/1/2012#
i've even tried using the DateValue function around the manual date i'm testing with but i still get the mismatch error:
WHERE DateValue(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' ')))) > DateValue("4/1/2012")
any tips on how i can compare a date in this method? i can't change any fields in the database, ect, that's why i'm parsing the date in SQL and trying to manipulate it so i can run reports against it.
i've tried googling but nothing specifically talks about parsing a date from text and converting it to a date object. i think it may be a bug or the way the date is being returned from the left/trim functions. you can see i've added a column to the end of the SELECT statement called DateTest and it's obvious access is treating it like a date (when the query is run, it asks to sort by oldest to newest/newest to oldest instead of A-Z or Z-A), unlike the second column in the select.
thanks in advance for any tips/clues on how i can query based on the date.
edit:
i just tried the following statements in my where clause and still getting a mismatch:
CDate(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' ')))) > #4/1/2012#
CDate(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' ')))) >
CDate("4/1/2012") CDate(DateValue(Trim(Left([bc_TestingTickets].[notes],InStr([bc_TestingTickets].[notes],' '))))) > #4/1/2012#
i tried with all the various combinations i could think of regarding putting CDate inside of DateValue, outside, ect. the CDate function does look like what i should be using though. not sure why it's still throwing the error.
here's a link to a screenshot showing the results of the query http://ramonecung.com/access.jpg. there's two screenshots in one image.
You reported you get Data Type Mismatch error with this WHERE clause.
WHERE DateValue(Trim(Left([bc_TestingTickets].[notes],
InStr([bc_TestingTickets].[notes],' ')))) > #4/1/2012#
That makes me wonder whether [bc_TestingTickets].[notes] can ever be Null, either because the table design allows Null for that field, or Nulls are prohibited by the design but are present in the query's set of candidate rows as the result of a LEFT or RIGHT JOIN.
If Nulls are present, your situation may be similar to this simple query which also triggers the data type mismatch error:
SELECT DateValue(Trim(Left(Null,InStr(Null,' '))));
If that proves to be the cause of your problem, you will have to design around it somehow. I can't offer a suggestion about how you should do that. Trying to analyze your query scared me away. :-(
It seems like you are having a problem with the type conversion. In this case, I believe that you are looking for the CDate function.
A problem might be the order of the date parts. A test in the Immediate window shows this
?cdate(#4/1/2012#)
01.04.2012
?cdate(#2012/1/4#)
04.01.2012
Write the dates backwards in the format yyyy/MM/dd and thus avoiding inadverted swapping of days and months!
DateValue("2012/1/4")
and
CDate(#2012/1/4#)