Convert variable to its content in sql (1 Viewer)

doobybug1

Registered User.
Local time
Yesterday, 19:58
Joined
May 22, 2012
Messages
36
I have the following sql statement and I cannot get the value saved in the variable title which is of type String. Any help please?

Code:
strSQL = "SELECT [Title], [ContractNo] FROM [tblActInfo] WHERE ((([Title] Is Null) or ([ContractNo] Is Null)) Or (([Title] Like  ' *  &  title & * ') or ([ContractNo]=contractNo)))"
 

Ranman256

Well-known member
Local time
Yesterday, 22:58
Joined
Apr 9, 2015
Messages
4,339
Your quotes are wrong.....try:

...[title] Like '*" & title & "*') or .....

Your string must be outside the quotes to resolve.
Or use a query ,not SQL.
 

doobybug1

Registered User.
Local time
Yesterday, 19:58
Joined
May 22, 2012
Messages
36
I think the syntax is good now but the result that I am getting is all the records...I entered only the contractNo expected that I am searching by contractNo and the title field is blank I will get the equality of the contractNo...this is how the query looks in the design view. Am I missing something?
 

Attachments

  • capture.PNG
    capture.PNG
    11.1 KB · Views: 65

doobybug1

Registered User.
Local time
Yesterday, 19:58
Joined
May 22, 2012
Messages
36
Sorry ignore my previous post...I realised I was writing the integer value incorrect in the sql...however I still think that the title is written wrongly as it is giving me wrong results. I outputted the sql and I attached it below. I think the sql should read: Like "*" & "cattle" & "*"

How can I fix the syntax to reflect this?
 

Attachments

  • capture.PNG
    capture.PNG
    3.3 KB · Views: 53

Users who are viewing this thread

Top Bottom