|
-
Mar 22nd, 2002, 10:08 AM
#1
Thread Starter
New Member
like statements with variables
hi all,
I have been trying to use a sql like statement with a variable and it doesn't seem to be working...
.....fieldname LIKE 'variable%'
...... " " variable%
...... " " "'variable%'"
Does anybody know the proper syntax?...I know it's possible to do it in ASP so it has to be possible in VB
Thanx in advance
SozeWun
-
Mar 22nd, 2002, 10:15 AM
#2
Hi
Try something like :
Dim strSql as string
Dim lngVar as Long
strSql="Select ... From....Where fieldname=" & lngVar & " Order By..."
Just add ' for text and # for dates around them so the resulting string of sql looks right (basic string manipulation - should be the same in ASP).
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Mar 22nd, 2002, 10:47 AM
#3
Here is an example from one of my projects
VB Code:
sqlstr = "SELECT pa_code, name, street, city, state "
sqlstr = sqlstr & "FROM qcap_dealer WHERE city LIKE '" & txtSrchCity.Text & "%' ORDER BY name"
Hope this helps.
-
Mar 22nd, 2002, 11:14 AM
#4
Thread Starter
New Member
here's my sql statement:
x=txtCriteria.text
.
.
.
.CommandText = "select CompanyName,PropertyRollNumber from tblMainContactClient CC join tblMainProperty MP on CC.ClientNumber=MP.ClientNumber where MP.PropertyRollNumber LIKE ' " & x & "%' "
Still doesnt work....i've even tried it in SQL Analyzer....wut am i doing wrong?
SozeWun
-
Mar 22nd, 2002, 11:41 AM
#5
Frenzied Member
Just a wild shot in the dark, but PropertyRollNumber is a char/varchar field isn't it? If not, you're probably going to have to cast it before you can use LIKE.
-
Mar 22nd, 2002, 11:44 AM
#6
Thread Starter
New Member
yup its a varchar...
Sozewun
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|