Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 4th, 2009, 04:26 PM
palmerj palmerj is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 5 palmerj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 42 sec
Reputation Power: 0
VBScript - SQL "LIKE" not working as expected

Hi Everyone,

I have a simple VBScript to read the contents of an Access 2003 database.

The database contains only 6 rows (4 columns):

ID,LastName,FirstName,Age
1,Petra,Andrea,15
2,Petrosky,Mathew,35
3,Smith,John,30
4,Smith,Alfred,20
5,Smithy,Sandra,22
6,Zorba,Andy,20

The VBScript shown below works but only if I remove the "*" from the value of the LIKE clause. For example, LIKE 'Smith' returns records 3 and 4, but if I code LIKE 'Smith*' nothing is returned.

I would expect it to returns records 3, 4 and 5.

When I run the same SQL inside Access, it works.

The column LastName is indexed in the table.

Any help greatly appreciated.
John.

------------------------------

Dim rs
Dim conn
Dim strConnect

Set conn = CreateObject("ADODB.Connection")
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\Database1.mdb"
conn.Open strConnect
strSQLQuery = "SELECT Table1.ID, Table1.LastName, Table1.FirstName, Table1.Age FROM Table1 WHERE (((Table1.LastName) LIKE'" & "Smith*'))"
Set rs = CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3
cntr = 0
While Not rs.eof
cntr = cntr + 1
WScript.Echo(rs(0) & "," & rs(1) & "," & rs(2) & "," & rs(3))
rs.MoveNext
Wend
conn.close
Set conn = Nothing
WScript.Echo("Records returned: " & cntr)
WScript.Quit(0)

Reply With Quote
  #2  
Old February 5th, 2009, 01:53 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,905 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 11 h 14 m 51 sec
Reputation Power: 969
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
You should use a % instead of a *. Also you have a syntax problem in the code you posted above. The end of your query should look like this:

LIKE 'Smith%'

vb Code:
Original - vb Code
  1. Dim rs
  2. Dim conn
  3. Dim strConnect
  4.  
  5. Set conn = CreateObject("ADODB.Connection")
  6. strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\Database1.mdb"
  7. conn.Open strConnect
  8. strSQLQuery = "SELECT Table1.ID, Table1.LastName, Table1.FirstName, Table1.Age FROM Table1 WHERE (((Table1.LastName) LIKE 'Smith%'))"
  9. Set rs = CreateObject("ADODB.Recordset")
  10. rs.Open strSQLQuery, conn, 3, 3
  11. cntr = 0
  12. While Not rs.eof
  13.     cntr = cntr + 1
  14.     WScript.Echo(rs(0) & "," & rs(1) & "," & rs(2) & "," & rs(3))
  15.     rs.MoveNext
  16. Wend
  17. conn.close
  18. Set conn = Nothing
  19. WScript.Echo("Records returned: " & cntr)
  20. WScript.Quit(0)
__________________
Don't like me? Click it.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!

Help us help you! Post your exact error message with these easy tips!

Reply With Quote
  #3  
Old February 5th, 2009, 11:04 AM
palmerj palmerj is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 5 palmerj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 42 sec
Reputation Power: 0
Talking That fixed it!

Thank you so much!

You rock.

Reply With Quote
  #4  
Old February 5th, 2009, 04:26 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,905 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 11 h 14 m 51 sec
Reputation Power: 969
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Quote:
Originally Posted by palmerj
Thank you so much!

You rock.
Awesome! Glad I could help out.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > VBScript - SQL "LIKE" not working as expected


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek