Need help with a SQL Statement!

  • Thread starter Thread starter David Hearn
  • Start date Start date
D

David Hearn

I have a DropDownList on one of my ASP.NET pages. The dropdown is
filled with the numbers 0-9 and the alphabet (A-Z). I have a field in
my database with some codes in it. The code may be something like 0AB
or BNY or 3YV. You get the idea. I need to run a SQL statement to
retrieve all records where the first letter or number of that code
field matches whatever the user selected from the dropdown. In other
words, if the user chooses 3, it should find all records where the
code begins with 3 and if they choose J, all records that begin with
J, no matter what the last two characters are. Can someone help me
with this?

Thanks in advance!
 
I don't know what your dropdown is called on your asp page, or your
tables/columns in your database, but the sql statement syntax you're looking
for is the LIKE keyword:

SELECT * FROM <table> WHERE <code field> LIKE '<letter in dropdown>%'

Where % is the wildcard operator. This, of course, will return all the
records in <table> that begin with <letter in dropdown>

Hope this is enough,
Blake
 
Thank you Blake!

I don't know what your dropdown is called on your asp page, or your
tables/columns in your database, but the sql statement syntax you're looking
for is the LIKE keyword:

SELECT * FROM <table> WHERE <code field> LIKE '<letter in dropdown>%'

Where % is the wildcard operator. This, of course, will return all the
records in <table> that begin with <letter in dropdown>

Hope this is enough,
Blake
 
Back
Top