MySQL Missing operand near Like - mysql

I am trying to filter a datagridview by the ID number, It keeps throwing an error ('Missing operand before 'Like' operator')
I keep getting this error only when filtering by a table ID column. It works fine if I filter by ('First_Name') or anything else but will not let me filter by ID. Any ideas?
Me.WelderNamesTableAdapter.FillBy(MacroQualityDataSet.welderNames)
Me.WelderNamesBindingSource.Filter = ("CONVERT(welderID, System.String) + [welderID] + LIKE + '%" & welderIDtxtbx.Text & "%'")

The + is not helping you here if welderID is a number that will not work.
This might
Me.WelderNamesTableAdapter.FillBy(MacroQualityDataSet.welderNames)
Me.WelderNamesBindingSource.Filter = ("CONVERT(System.String,welderID) LIKE + '%" & welderIDtxtbx.Text & "%'")

Related

Dlookup returning number as text

The DLookup is returning number values as text. Thoughts on what's either wrong with my code or reasons why that would happen? I'm hoping it's something simple.
Sort: DLookUp("Sort","contacts_rank_CurrentRank","ContactID = " & [ID])
I've tried to Format as "General Number" but that doesn't transform the value back to a number
I've tried the below formula but that results in "Error"
Sort: DLookUp("Sort","contacts_rank_CurrentRank","ContactID = '" & [ID] & " ' ")
Visual of the data in the query I'm looking up the data from. Sort Column in Contacts_Rank_CurrentRank
Value that is being returned with the dlookup
You don't really need a dlookup here - a sql left join against that table will run at least 100x times faster.
But, you can do this if performance is not a issue:
clng(DLookUp("Sort","contacts_rank_CurrentRank","ContactID = '" & [ID] & " ' "))

Dlookup with multiple criteria return the same result

When I run the following query,
Dlookup("[Service Description]","[Roster_QC]","[ID]=" & [ID]-1 AND "'[Person]= '" & [Person]&"'")
It showed the same result every time.
What I try to achieve is to let the Dlookup return for the previous service description when the person is the same.
Appreciate your insights or solution to this. Thanks.
Have an extraneous apostrophe and incorrect concatenation.
Dlookup("[Service Description]", "[Roster_QC]", "[ID]=" & [ID]-1 & " AND [Person]= '" & [Person] & "'")
That approach assumes there are no gaps in ID sequence. If there are gaps, expect incorrect results. Alternative query where gaps are irrelevant:
SELECT Roster_QC.*, (SELECT TOP 1 Dupe.[Service Description] FROM Roster_QC AS Dupe
WHERE Dupe.Person = Roster_QC.Person AND Dupe.ID<Roster_QC.ID
ORDER BY Dupe.ID DESC) AS Prev
FROM Roster_QC;

Apostrophe in sql string how can I remove

I need some help. I use a combo box to create a sql query. Here is the query string
SQlstr = "UPDATE maindata SET " _
& "?theoption1 = ?therec1 " _
& "WHERE acct = ?theaccount AND clientnumber=?theclient;"
?theoption1 is a field name but it comes out with an apostrophe like 'xxxxx' , and this causes an error. How do I get around this. I cant use Replace because I am using parameters.
Thanks for any help I can get.

SQL UPDATE based on condition

We need to update a table with the users id (NBK). The table with NBK also has the user status (0 - 1) and only one user will have 1 at a time. The challenage is to #1 capture the active user #2 update the other table with the user NBK. I hope the code below just has a simple syntex error that I cannot find?
Dim nb As String
Dim NBK As String
nb = [Employees]![NBK] & "' WHERE "
nb = nb & " " & [Employees]![Status] = '1'
NBK = " Update tbl_DateTracking SET NBK = "
NBK = NBK & "'" & nb & "' WHERE "
NBK = NBK & "CaseId = '" & CaseId & "' AND OCC_Scenario = '" & OCC_Scenario & "' ;"
DoCmd.RunSQL nb
DoCmd.RunSQL NBK
Several pointers of note here:
You should use parameterized queries instead of string concatenation. This prevents/contains SQL injections and other issues regarding malformed input.
Ideally, you should normalize the database so that "active user" is not a field on the user table. What happens when there are two users set as "active" in the database?
With this given schema however, you're going to want to use a sub-select query. Ex:
UPDATE tbl_DateTracking SET NBK=(SELECT NBK FROM Employees WHERE Status=1 LIMIT 1) WHERE CaseID=? AND OOC_Scenario=? and then pass in CaseId and OOC_Scenario as the parameters.
Note, I'm not familiar with VB or how it interacts with SQL; The above is just an example, you'll have to apply it to your application and alter it to make it work. The way you're building and running the nested queries also looks like it won't work, since your first query doesn't contain a command (You probably want SELECT, I think. Does VB do that automatically with []![] syntax?), and when you nest it inside the second query, it's not surrounded with (). Running the first query by itself also has no effect if you're including it as a sub-query in the second one.

ASP and Acess DB - "Like" Query problem

//ACCESS
SELECT DISTINCT products.imageUrl FROM products WHERE ((products.pcprod_ParentPrd=5573) AND (products.pcprod_Relationship LIKE '*441*'));
//ASP
SELECT DISTINCT products.imageUrl FROM products WHERE ((products.pcprod_ParentPrd="&pidProduct&") AND (products.pcprod_Relationship LIKE '*"&rsCS("idoptoptgrp")&"*'));
this query works when i'm manually running the query in Access database. but when I run it from ASP. it doesn't return and rows
#user670111: In your ASP you have to use % instead of * as the wild-card character.
So rewrite your query in ASP as
SELECT DISTINCT products.imageUrl FROM products WHERE (products.pcprod_ParentPrd = " & pidProduct & ") AND (products.pcprod_Relationship LIKE '%" & rsCS("idoptoptgrp") & "%')
Maybe the values of pidProduct & rsCS("idoptoptgrp") are not what you are expecting it to be?
Does it work when you try ...
((products.pcprod_ParentPrd=" & 5573 & ") AND (products.pcprod_Relationship LIKE '*" & 441 & "*'));