Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6848747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:54:25+00:00 2026-05-27T00:54:25+00:00

Tried a query first like this SELECT * FROM CUSTOMER WHERE LEFT(NAME, 1) =

  • 0

Tried a query first like this

SELECT *
FROM CUSTOMER
WHERE LEFT(NAME, 1) = 'A'

which worked fine, but now I want it as a stored procedure and ‘A’ being replaced by a search term like this

CREATE PROCEDURE [dbo].[procCustomer_SelectByFirstLetter]
    @SearchTerm VARCHAR(50)
AS
SELECT  [Name]

FROM    [dbo].[Customer]
WHERE   LEFT(NAME, 1) = '@SearchTerm'
GO

this stored procedure is called by a C# method which uses a dropdown list with all the letters A-Z

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {


            DataTable customerTable =  Customer.SelectByFirstLetter(Request.QueryString[DropDownList1.SelectedValue.ToString()]);
            CustomerRepeater.DataSource = customerTable;
            CustomerRepeater.DataBind();
            CustomerCountLabel.Text = customerTable.Rows.Count.ToString();            
    }

the Reapter shows nothing though when I select a letter from the drop down. Any ideas? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:54:25+00:00Added an answer on May 27, 2026 at 12:54 am

    You’re still using the quoted value, so it looks for a name where the first letter equals the string "@SearchTerm", which of course nothing ever will.

    You’ll need to remove the quotes:

    WHERE LEFT(NAME, 1) = @SearchTerm
    

    Additionally, you may or may not be aware that you can achieve this with LIKE:

    WHERE NAME LIKE 'A%'
    

    … Or

    WHERE NAME LIKE @SearchTerm + '%'
    

    … Where the % is wildcard for anything. In this way, passing A will search for anything starting with the letter A, but passing ABC will search for anything with the letters “ABC”, without having to specify the length, as in your LEFT function.

    Update
    Additionally, you seem to be passing the parameter to the procedure incorrectly:

    DataTable customerTable = Customer.SelectByFirstLetter(Request.QueryString[DropDownList1.SelectedValue.ToString()]);
    

    Here, you’re looking for a key in the QueryString collection, matching your selected value. So if DropDownList1.SelectedValue.ToString() yields “A”, it’ll be looking for ?A=.... You probably want to use the following instead:

    DataTable customerTable = Customer.SelectByFirstLetter(DropDownList1.SelectedValue.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my code is this, $query = SELECT * FROM `cars` WHERE (color LIKE '%.
I have this elementary query: SELECT d.description, o.code FROM order_positions AS o LEFT JOIN
I have customer and address tables. Query: SELECT * FROM addresses a, customers b
i want something like this: SELECT DISTINCT ID from copies WHERE timestamp < 1229444506
I am using psql 8.1.18 on Glassfishserver. I have a query like this: select
I've tried this: SELECT first_name,last_name,company_name FROM users ORDER BY last_name, company_name ASC I have
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
This should be something encountered by programmers often, but I never tried to get
UPDATE based on the answer by @BrianFisher below, I tried this: SELECT np.id AS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.