Hi
I have an array like this: myArray(n) ,and I need to make a dynamic WHERE
clause
e.g
Where Value = myArray(0) or myArray(1)...
But the where clause can not be explicit because the length of the array is
variable
What is a professional way to do something like this?
ThksAre you just using T-SQL or are you using VB in the front end?
"Kenny M." <KennyM@.discussions.microsoft.com> wrote in message
news:18A39651-A7B4-4208-9C52-515BC1198955@.microsoft.com...
> Hi
> I have an array like this: myArray(n) ,and I need to make a dynamic WHERE
> clause
> e.g
> Where Value = myArray(0) or myArray(1)...
> But the where clause can not be explicit because the length of the array
> is
> variable
> What is a professional way to do something like this?
> Thks
>|||Check out this article on ASPFAQ to get started:
http://www.aspfaq.com/show.asp?id=2248
"Kenny M." <KennyM@.discussions.microsoft.com> wrote in message
news:18A39651-A7B4-4208-9C52-515BC1198955@.microsoft.com...
> Hi
> I have an array like this: myArray(n) ,and I need to make a dynamic WHERE
> clause
> e.g
> Where Value = myArray(0) or myArray(1)...
> But the where clause can not be explicit because the length of the array
> is
> variable
> What is a professional way to do something like this?
> Thks
>|||>> What is a professional way to do something like this? <<
Put the values in the only data structure allowed in SQL, a table
WHERE x IN (SELECT x FROM Parmlist
)|||Yeah the code is in VB, is not transac but I would like to know how to make
it too.|||On the VB.NET side, create the SQL Statement dynamically using a String
variable and a For Loop:
Dim sqlstr As String
sqlstr = "SELECT * FROM table1 WHERE col1 IN ("
For i = 0 To MyArray.Length - 1
sqlstr += CType(MyArray(i), String)
If i < MyArray.Length - 1 Then
sqlstr += ","
End If
Next
sqlstr += ")"
"Kenny M." <KennyM@.discussions.microsoft.com> wrote in message
news:5897F0E6-FBE8-4BF4-97B4-DBD5A943DDB4@.microsoft.com...
> Yeah the code is in VB, is not transac but I would like to know how to
> make
> it too.|||pretty good thks
--
Kenny M.
"Michael C#" wrote:
> On the VB.NET side, create the SQL Statement dynamically using a String
> variable and a For Loop:
> Dim sqlstr As String
> sqlstr = "SELECT * FROM table1 WHERE col1 IN ("
> For i = 0 To MyArray.Length - 1
> sqlstr += CType(MyArray(i), String)
> If i < MyArray.Length - 1 Then
> sqlstr += ","
> End If
> Next
> sqlstr += ")"
>
> "Kenny M." <KennyM@.discussions.microsoft.com> wrote in message
> news:5897F0E6-FBE8-4BF4-97B4-DBD5A943DDB4@.microsoft.com...
>
>
No comments:
Post a Comment