Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2007, 02:46 AM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call many item in LIKE?

Hello, can anyone show me how to get array for many item by using function "LIKE" in visual basic application

Example:

Dim count integer
Dim part() as string

For i = o to i =count step 1
Sql = "SELECT DISTINCT TOP 65535 T1.A,T1.B " & _
      "FROM Table1 " & _
      "WHERE T1.A LIKE '" & part[1]& "%' " & _


But the array [1] got error. Please advise me for the above problem.
Thanks for help

apple
__________________
apple
 
Old June 17th, 2007, 11:08 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Not sure your FOR statement is correct... Did you mean to use an "o" (lowercase "oh") instead of an "0" (zero) and do you mean to overwrite the value of "i"? I'm thinking you need something more like this...

FOR x = 0 to i STEP 1

Sql = "SELECT DISTINCT TOP 65535 T1.A,T1.B " & _
     "FROM Table1 " & _
     "WHERE T1.A LIKE '" & part[x] & "%' " & _



--Jeff Moden
 
Old June 17th, 2007, 07:25 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, Jeff

Thanks for your reply. Let'me answer your question first. The 0 is represented zero. The value will not overwrite because i want to view all the the user key item. Do you have any idea to solve this problem?

apple
 
Old June 18th, 2007, 07:34 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Ok, if you say so... the "o" you posted is a lower case "oh", not a zero.

Would be helpful if you posted what the error was... other than that, I'm out of tricks on this one.

--Jeff Moden
 
Old June 18th, 2007, 11:54 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jeff,

This is the error

Run-time error '1004':

SQL Syntax Error.



apple
 
Old June 19th, 2007, 06:20 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Not very helpful error listing, is it?

I do notice that you have a final "& _" in the posted code. Anything follow that? I think the best way to troubleshoot this is going to be to print the value of the SQL variable to see what it's actually doing.

--Jeff Moden
 
Old June 20th, 2007, 06:45 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jeff,

At the back symbol _( underscore) is means concanate (&) of the Sql. I am thinking is it i should declare variable to solve my error?
For example declare :
Dim part()

The sql cant print out. Syntax error

apple
 
Old June 20th, 2007, 07:27 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

I know the "_" symbol means continue on the next line... what is the next line after the WHERE clause (it also has the "_")?

Also, you might be better off posting your question on a VB forum...

--Jeff Moden
 
Old June 20th, 2007, 09:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is not going to execute one giant sql statement; it is going to execute MANY SELECT statements.

You need something like

Dim sSqlMaster, sSqlLike
sSqlMaster = ""SELECT DISTINCT TOP 65535 T1.A,T1.B " & _
      "FROM Table1 " & _
      "WHERE T1.A "

For i = 0 to i =count step 1
sSqlLike = sSqlLike & "LIKE '" & part[i]& "%' AND T1.A "
Next

sSqlMaster = sSqlMaster & Left(sSqlLike, (Len(sSqlLike) - 10))
Your string will also have a trailing AND T1.A which you will need to remove which is what the LEFT() function is doing. (I am assuming that you are using classic ASP based upon your other posts in the forum)
hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 24th, 2007, 11:01 AM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dparsons,

Thanks for your explanation. Can u elaborate more for this syntax
sSqlMaster = sSqlMaster & Left(sSqlLike, (Len(sSqlLike) - 10))?
I not understand : -10. Hope to hear from you soon. Thanks


apple





Similar Threads
Thread Thread Starter Forum Replies Last Post
Item Templates hbansal ASP.NET 1.0 and 1.1 Professional 6 August 2nd, 2007 06:24 AM
count item urbanaccess Access 1 January 16th, 2007 12:33 PM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM
Find Out First Item of each item Group Jane SQL Language 1 November 22nd, 2003 12:42 PM
? DataGrid Item [email protected] ASP.NET 1.0 and 1.1 Professional 0 November 18th, 2003 08:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.