Why am I getting the Missing Operator error? - sql

I keep getting the same error: Missing Operator. I have looked over this code three times and cannot find it. Can someone with a keen eye please help?
WHERE ([Letter Status].[Letter_Status] = “Agreed” AND [Research].[Site] = 9)
OR ([Telephone Status].[Details]= “Agreed” AND [Research].[Site] = 9)

I'm not sure about that “”
Maybe is from this post, but change them to "" :
WHERE ([Letter Status].[Letter_Status] = "Agreed" AND [Research].[Site] = 9)
OR ([Telephone Status].[Details]= "Agreed" AND [Research].[Site] = 9)

Usually it is a misspelled table or field name, two spaces instead of just one, a space instead of "_", any missing letter or something like that.
Create a new query in MS Access and put the whole query in, then run it. The Access GUI most probably tells you more detailed what exactly is missing here.

Related

Why am I getting a `Data type mismatch` error when I add "CF" to the end of my search string in a SQL statement in Access?

The following query (qryCurLotNewProducts) produces a data set that I want process further with another query (qryBNP_CFRecordset):
//qryCurLotNewProducts
SELECT tblNewProducts.*
FROM tblNewProducts INNER JOIN tblCurLot ON (tblCurLot.CatalogNum = tblNewProducts.CatalogNum) AND
(tblNewProducts.LotNum = tblCurLot.CurLot);
When I run this second query to list only the "CF" products found in the first query, I get the `Data type mismatch in criteria expression' error.
//qryBNP_CFRecordset
SELECT qryCurLotNewProducts.*, tblABCategory.UNSPSC, tblAmount.ProductSize
FROM tblAmount RIGHT JOIN (tblABCategory RIGHT JOIN qryCurLotNewProducts ON tblABCategory.ABCategory = qryCurLotNewProducts.ABCategory) ON tblAmount.Amount = qryCurLotNewProducts.Amount
WHERE (((qryCurLotNewProducts.CatalogNum) Like "A700-###CF") AND ((qryCurLotNewProducts.DateEntered) Between #1/1/2000# And #3/1/2020#))
ORDER BY qryCurLotNewProducts.CatalogNum, Abs(qryCurLotNewProducts.LotNum);
If I remove the CF from the search string (so "A700-###"), the query correctly outputs a list containing all items that contain that pattern:
If I use strings like "A700-####F" or "A700-###ZZ" or other combinations like that, I don't get an error but rather an empty results set.
Notably, "A700-001CF", "A700-002CF", etc all create the data type error. It seems there is something about the CF key combination that is causing trouble.
Has anybody else ever seen this issue? Do I need to use some kind of delimiter to tell SQL to not view CF as some kind of special switch?
Abs(qryCurLotNewProducts.LotNum) wont work with the values for Products ending in CF. Your LotNum-Column has a text-type.
Edit: Your LotNum-Column has a text-type as you can see in your first screenshot.

VB.NET - LINQ - dbContext - Where - Letter is not declared error. Trying to update single record

I'm in the process of writing an update code to update user information on an asset used for a project I have. The code is below...
AlteredUser = dbContext.Assets.Where(c >= c.ParentAssetID = ParentAssetId And c.AssetDecription = "USER").SingleOrDefault()
AlteredUser.AssetName = UserName
dbContext.SubmitChanges()
I'm getting an error message saying " 'c' is not declared ". I've seen several examples of how to use the where clause within dbContext, and all of them use a letter as LINQ normally does. I cannot figure out why it is erroring out for me.
Any help would be greatly appreciated.
Thank you!
>= is a comparison operator.
To create a lambda in VB, write
Function(c) c....

Adding an error message to return. SQL Server

Well, I'm trying to construct some error reporting.
Current snippet of code, which will put into a stored procedure after I get this code correct...
begin
select *
from dbo.DIM_S17_Detail
Where ((LEN(New_Acc_Flag) >1 or ISNUMERIC (Substring(New_Acc_flag, 1, 1)) = 1))
end
So, the defined datatype is either a Y/N - Alphanumeric, so it picks out ISNUMERIC as 1, so it will bring up the selected records which ARE numeric - so these records are incorrect...
I hope you still follow...
So, if a 'New_Acc_Flag' is TRUE, it will bring up those record(s) and should return a message something like "Y/N not selected" or "Y/N Value only".
Thanks again.
Please bear in mind I'm a noobie to SQL.
If I understand what you want correctly you can use THROW or RAISERROR

create variable as a function of another variable in SQL

Okay. Basically, I want to define a complex variable within a SQL statement and then define another variable as a "function" of the first. I've searched around and can find no indication of how I might accomplish this. I can always just copypaste the code, but that makes it SO messy! See my (erroneous) example below. true file is the first variable and location is the second.
select
true_file = RIGHT(url.FULL_PATH, CHARINDEX('/',REVERSE(url.FULL_PATH)) - 1),
location = RIGHT(url.FULL_PATH, LEN(url.FULL_PATH) - LEN(true_file) - 9)
from files f
join BBLEARN_cms_doc.dbo.XYF_URLS url
on url.FILE_ID = substring(f.file_name, 6, len(f.file_name) - 7)
where f.file_name like '/xid-%'
order by url.FULL_PATH;
But obviously, we get an "invalid column name" error when trying to run any functions on true_file. What's the best way to do this?

How to remove from one list all the items in another?

I'm reading a set of rows from a remote database, and a similar set from a local database, and then using RemoveAll to get rid of remote rows that are already present locally...
remote_events = (From a In remote.Events
Where ...etc...).ToList
local_events = (From a In local.Events
Where ...etc...).ToList
remote_events.RemoveAll(Function (ByVal event_row As Remote_Event)
(From a In local_events Where a.Identifier = event_row.Identifier).Count > 0)
but this doesn't seem right to me. I don't think I should be counting things when all I really need to do is check whether a match exists. I've tried various usages of IsDBNull and IsNothing but get nonsense. I can't use .Except (as suggested here) because the list elements are not the same type.
Is there a better way of doing this?
One way is this:
remote_events.RemoveAll(Function(e) local_events.Exists(Function(f) f.Identifier = e.Identifier))
I'm trying to do this without visual studio, so I'm not sure if this will work, but I'd suppose you could do something along these lines if what you're trying to do is compare the Identifier:
Remote_Events = (From r_evt In Remote_Events
Where Not ((From l_evt In Local_Events Select l_evt.Identifier).Contains(r_evt.Identifier))
Select r_evt).ToList
I hope this helps and at least moves you in the right direction.