Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question - How to append wildcard to variable

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
I need to append a wildcard symbol to a variable ("strFacStaffName")passed from a form. So far, every atempt to insert a "%" in this statement has resulted in an error:
SELECT Lastname, Lastname2, Firstname, Title, Department, Phone, Fax, Email, Building, Office FROM Table1 WHERE Lastname like '"& strFacStaffName &"' OR Lastname2 Like '" & strFacStaffName &"';"

What is the correct syntax for this?
 
cactus1000,

You should place the percent sign within the single quotes.

SELECT Lastname, Lastname2, Firstname, Title, Department, Phone, Fax, Email, Building, Office FROM Table1 WHERE Lastname like '%" & strFacStaffName & "%' OR Lastname2 Like '%" & strFacStaffName & "%';"

fengshui_1998

 
Thanks - -This works great!

Now, I have one last question:

The output should look like this:

Smith, Charles

However, it comes out as

Smith , Charles

The space between the last name and the comma seems to be caused by the "Lastname2" field being included in the Sql statement. Why would this cause a space to appear in the output when there is nothing in this field?

Here's my output line:

Response.Write &quot;<tr><td><b><i><font color='#000066'>Name:</b></i></font></td><td>&quot; & objRS(&quot;Lastname&quot;) & &quot; &quot; & objrs(&quot;Lastname2&quot;)&&quot;, &quot; & objRS(&quot;Firstname&quot;) & &quot;</td></tr>&quot;
 
you inserted that extra space, see what i highlighted in red.. i'd use an If statement, if anything in Lastname2, then put space and Lastname2, else not.....

Response.Write &quot;<tr><td><b><i><font color='#000066'>Name:</b></i></font></td><td>&quot; & objRS(&quot;Lastname&quot;) & &quot; &quot; & objrs(&quot;Lastname2&quot;)&&quot;, &quot; & objRS(&quot;Firstname&quot;) & &quot;</td></tr>&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top