Showing posts with label selecting. Show all posts
Showing posts with label selecting. Show all posts

Friday, March 9, 2012

query database user input from ListBox

I have a problem selecting fields from a table where fields are equal to user input from a listbox. example

listbox of zip codes:

33023
[red]22300[/red]
39844
[red]29339[/red]
23883
[red]38228[/red]

user wants to retreive highlight zip codes from database.
connection working perfect.
Thank you for your help.


you could use IN. check out books on line for more info.

SELECT

<columnlist>

FROM

yourtable

WHERE

zipcode IN ( ....)

|||

Hi There:

You need to retrieve the selected item from yous listbox first. Like this:

<code>

Dim sYourZipString As String = nothing
Dim sItem As ListItem
For Each sItem In zipListBox.Items
If sItem.Selected Then
sYourZipString = sYourZipString & "'" & sItem.Text & "', "
End If
Next

sYourZipString = sYourZipString.Remove(sYourZipString.Length-2, 2) ' remove the tail

</code>

You can use a select IN clause with a parameter which use the value(s) user.

Assume zipcode field is a text field (Char(5), or varchar(5) something not a number).


<code>
Dim conn As SqlConnection
Dim yourcmd As SqlCommand
Dim strConn as string = "yourconnection"

Dim yourSQLString As String
yourSQLString ="Select * FROM youTableIncludeZip WHERE zipcode IN (@.YourZipString)"

conn = New SqlConnection(strConn)

yourcmd = New SqlCommand(strUpdateStmt, conn)
yourcmd.Parameters.Add(New SQLParameter("@.Fname", txtFirstName.text))

Dim objDR as SQLDataReader
dim yourItem1fromDB as string =nothing
dim yourItem2fromDB as string =nothing
dim yourItem3fromDB as string =nothing

Try
conn.Open()
objDR=yourCmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

While objDR.Read()

yourItem1fromDB=objDR("yourItem1")
yourItem2fromDB=objDR("yourItem2")
yourItem3fromDB=objDR("yourItem3")
' ... get what you want from you Db table
End While

Finally
conn.close

End Try

</code>

Hope this help.


Limno

Wednesday, March 7, 2012

Query Confusion

Hello,
I have a large database and am trying to figure out why the following
queries differ so much in speed. I am selecting from two tables related by a
unique ID field. There are approximately 26mil rows of data in each table.
select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in about 7 seconds
select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in
My only guess is this. The only indexed fields in the query are v1.zip,
v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
simply a matter of the time it's taking MSSQL to fine the appropriate values
in the database file.
Can I split up my database into many filegroups and actually assign a
filegroup to specific tables?
Thanks.
and v2.f63=1;
stooky
Have you seen that query optimizer is available to use the index?
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;
|||The answer to the first query can be obtained from looking at the index
ONLY, without going to the table ... The index covers that query... The
second query includes a non-indexed column in the column list, so the rows
must be fetched - which would be much slower...
Search for 'Covering index' on google or in books on line...
Hope this helps
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
> a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
> OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
> values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;

Query Confusion

Hello,
I have a large database and am trying to figure out why the following
queries differ so much in speed. I am selecting from two tables related by a
unique ID field. There are approximately 26mil rows of data in each table.
select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in about 7 seconds
select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in
My only guess is this. The only indexed fields in the query are v1.zip,
v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
simply a matter of the time it's taking MSSQL to fine the appropriate values
in the database file.
Can I split up my database into many filegroups and actually assign a
filegroup to specific tables?
Thanks.
and v2.f63=1;stooky
Have you seen that query optimizer is available to use the index?
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;|||The answer to the first query can be obtained from looking at the index
ONLY, without going to the table ... The index covers that query... The
second query includes a non-indexed column in the column list, so the rows
must be fetched - which would be much slower...
Search for 'Covering index' on google or in books on line...
Hope this helps
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
> a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
> OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
> values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;

Query Confusion

Hello,
I have a large database and am trying to figure out why the following
queries differ so much in speed. I am selecting from two tables related by a
unique ID field. There are approximately 26mil rows of data in each table.
select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in about 7 seconds
select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
v1.zip=90210) AND v1.uid=v2.f1;
- this query completes in
My only guess is this. The only indexed fields in the query are v1.zip,
v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
simply a matter of the time it's taking MSSQL to fine the appropriate values
in the database file.
Can I split up my database into many filegroups and actually assign a
filegroup to specific tables?
Thanks.
and v2.f63=1;stooky
Have you seen that query optimizer is available to use the index?
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;|||The answer to the first query can be obtained from looking at the index
ONLY, without going to the table ... The index covers that query... The
second query includes a non-indexed column in the column list, so the rows
must be fetched - which would be much slower...
Search for 'Covering index' on google or in books on line...
Hope this helps
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"stooky" <stooky@.discussions.microsoft.com> wrote in message
news:0A0C35BA-8FF7-4FE6-B08A-BFE78B017DA5@.microsoft.com...
> Hello,
> I have a large database and am trying to figure out why the following
> queries differ so much in speed. I am selecting from two tables related by
> a
> unique ID field. There are approximately 26mil rows of data in each table.
> select v1.zip,v2.f1 from v1,v2 where (v1.zip=44122 OR v1.zip=56879 OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in about 7 seconds
> select v1.zip,v2.f1,v2.f63 from v1,v2 where (v1.zip=44122 OR v1.zip=56879
> OR
> v1.zip=90210) AND v1.uid=v2.f1;
> - this query completes in
> My only guess is this. The only indexed fields in the query are v1.zip,
> v1.uid and v2.f1. Due to the fact that the table v2 is quite large, it's
> simply a matter of the time it's taking MSSQL to fine the appropriate
> values
> in the database file.
> Can I split up my database into many filegroups and actually assign a
> filegroup to specific tables?
> Thanks.
> and v2.f63=1;