Use "IN" key word when compare city names.
The string should looks like
select * FROM MyTable WHERE City IN ('REDMOND', 'BELLVEUE', 'SEATTLE')
Note: You need quote string value by single quote, (escape single quote by
extra single quote).
If the data type of City is unicode (nchar, nvarchar) put a capital N
before it, it looks like N'REDMOND' .
Lishi, VSData Team
--------------------
[quoted text, click to view] >From: "Scott Reynolds" <scott@it-xenius.co.uk>
>Subject: SQL query... is there a better way?
>Date: Tue, 18 Jan 2005 18:26:11 +0200
>Lines: 29
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-RFC2646: Format=Flowed; Original
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>Message-ID: <OXC1hpX$EHA.3416@TK2MSFTNGP09.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb.data
>NNTP-Posting-Host: 217-159-160-209-dsl.trt.estpak.ee 217.159.160.209
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
.phx.gbl
[quoted text, click to view] >Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb.data:4646
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb.data
>
>Hi,
>
>I am using following code to read and generate SQL query based on values
>stored in ArrayList. But I am not sure if it is the best way... all
>suggestions are
>welcome!
>
>Thank you!
>Scott
>
>
>Dim SqlQuery As String
>Dim SqlCity As String
>
>If Not Cities.Count = 0 Then
> For i As Integer = 0 To Cities.Count - 1
> If i = 0 Then
> SqlCity = "(City =" + Cities(i) + ")"
> Else
> SqlCity = SqlCity + " Or (City =" + Cities(i) + ")"
> End If
> Next
> SqlCity = "(" & SqlCity & ")"
>End If
>
>SqlQuery = "Select * FROM MyTable WHERE " & SqlCity
>
>
>
>