I am attempting in Access to show some data in a listbox, but only data which meets a certain condition should be displayed, however my SQL is flagging the error;
Syntax Error (missing operator) in query expression tblItem.[Status] WHERE (tblItem.[Status] = 'Unassigned
Here is my full query
`SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
WHERE (tblItem.[Status] = 'Unassigned') FROM tblItem;`
Where am i going wrong?
try this
SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
FROM tblItem
WHERE tblItem.[Status] = 'Unassigned'
I think You have misplaced the from and where clause
Remember the syntax for select:
SELECT ... FROM ... WHERE ... ORDER BY
Related
I got an error with the below SQL I wrote in ACCESS, where is my mistake? I've other when statements to add
UPDATE daily_inventory t0
SET
t0.Type = CASE
WHEN t0.[item number] LIKE "*-FG-*"
THEN "Float"
END
MS Access won't support CASE expression use IIF() instead :
UPDATE daily_inventory AS t0
SET t0.[Type] = IIF(t0.[item number] LIKE "*-FG-*", "Float", '<whatever>')
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.
SELECT
(
SELECT Sum(tbl_allTransactions.transAmount) AS SumOftransAmount
FROM tbl_allTransactions
WHERE (((tbl_allTransactions.[transType])='Expense')) OR (((tbl_allTransactions.[transType])='Budget') AND ((tbl_allTransactions.[transMonth])=[#transMonth]))
GROUP BY tbl_allTransactions.transMonth
,
SELECT Sum(tbl_allTransactions.transAmount) AS SumOftransAmount
FROM tbl_allTransactions
WHERE (((tbl_allTransactions.[transType])='Expense')) OR (((tbl_allTransactions.[transType])='Budget') AND ((tbl_allTransactions.[transMonth])=[#transMonth]))
GROUP BY tbl_allTransactions.transMonth
)
FROM tbl_allTransactions WHERE (((tbl_allTransactions.[userID])=[#userID]))
I am getting following error:-
System.Data.OleDb.OleDbException (0x80040E14) Syntax error in query
expression '(SELECT Sum(tbl_allTransactions.transAmount) AS
SumOftransAmount FROM tbl_allTransactions WHERE
(((tbl_allTransactions.[transType])='Expense')) OR
(((tbl_allTransactions.[transType])='Budget') AND
((tbl_allTransactions.[transMonth])=[#transMonth])) GROUP '. at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResulthr) at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Obje
The original code was missing a closing parenthesis on the first subquery. The code was also simplified by consolidating the transType conditional from 2 statements to 1. Extra brackets were removed to enhance readability. Also column aliases were added to output of each subquery. Since both queries render the same data, the second column was called "SumOftransAmount2"
SELECT
(SELECT Sum(tbl_allTransactions.transAmount)
FROM tbl_allTransactions
WHERE tbl_allTransactions.transType in ('Expense', 'Budget') AND tbl_allTransactions.transMonth = #transMonth
GROUP BY tbl_allTransactions.transMonth) as SumOftransAmount
,
(SELECT Sum(tbl_allTransactions.transAmount)
FROM tbl_allTransactions
WHERE tbl_allTransactions.transType in ('Expense', 'Budget') AND tbl_allTransactions.transMonth = #transMonth
GROUP BY tbl_allTransactions.transMonth) as SumOftransAmount2
FROM tbl_allTransactions
WHERE tbl_allTransactions.userID=#userID
When I trying the below SQL I am getting the error ORA-00936: missing expression. Please help me on this, I want distinct on those to columns in Oracle SQL
SELECT rr.RPT_QUE_I,
DISTINCT (rr.ed_sbmt_m, rr.RPT_RUN_STAT_C),
rr.rpt_cstm_x,
rr.rpt_cmplt_m,
CASE
WHEN rr.rpt_run_stat_c = 25453 THEN 'PENDING'
WHEN rr.rpt_run_stat_c = 25454 THEN 'ACTIVE'
WHEN rr.rpt_run_stat_c = 25455 THEN 'FINISHED'
WHEN rr.rpt_run_stat_c = 25458 THEN 'ERROR'
WHEN rr.rpt_run_stat_c = 25460 THEN 'SCHEDULED'
END,
cc.pro_sym_I,
rr.usr_wad_ownr_i
FROM audit_REPORT_RUN rr,
CLIENT_COMPANY cc
WHERE rr.ED_SBMT_M > TO_DATE('06/01/2012','mm/dd/yyyy')
AND rr.ED_SBMT_M < TO_DATE('07/01/2012','mm/dd/yyyy')
AND rr.ORG_I = cc.ORG_I
ORDER BY rr.RPT_QUE_I
You should use DISTINCT keyword at first after the SELECT keyword, and remove the parenthesis,
or if you need to categorize some of it, use GROUP BY functions. hope you're getting the desired result.
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...