• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Is it possible to use LEFT and WHERE in a sql statement

I am trying to produce a quick A-Z index of items stored in my database based on the initial letter of the product.

For instance, I will have

A B C D E F .... at the top of the page and then below it a dynamic table which will show only those products beginning with A etc

Is it possible to write something like as the SQL statement

SELECT "aaa,bbb,ccc from tbl_xxx where LEFT(aaa,1) = "+Request("Initial")

I am getting invalid column name

Is there an easy SQL way to do this...

1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, it would be something like this:
sql = "SELECT aaa,bbb,ccc from tbl_xxx where aaa LIKE '" +Request("Initial") + "%' "

Open in new window

Pratima PharandeCommented:
SELECT aaa,bbb,ccc from tbl_xxx where aaa  like '"+ Request("Initial") +"'%"
Pratima PharandeCommented:
actual query is like this

SELECT aaa,bbb,ccc from tbl_xxx where aaa  like 'a%'
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

roblickleyAuthor Commented:
"SELECT * FROM dbo.tbl_aaa where left(aaa,1) = '" + Request("Initial") + "'"

missed off the " !!
Guy Hengel [angelIII / a3]Billing EngineerCommented:
glad that you found your solution, note though that the LIKE method pratima_mcs and I suggest will result in eventually better performance, as it could use an index.
your method using LEFT() on the field will make that impossible...
Closed, 500 points refunded.
Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now