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 8980315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:03:36+00:00 2026-06-15T20:03:36+00:00

I am using this SQL statement to get rows: SELECT firstname, lastname FROM myTable

  • 0

I am using this SQL statement to get rows:

SELECT firstname, lastname 
FROM myTable 
WHERE ((lastname LIKE '" + parameter + "%')

parameter gets a value form a textbox. The default value of textbox is " "

My problem is I am getting all the rows when nothing is entered in the textbox. I tried to use

WHERE lastname = 

This simply gives me all the records that has " "

What is the correct way of getting data that excludes blanks in the database and also does not give your any record when blank or ” ” is passed as a parameter

  • 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-06-15T20:03:37+00:00Added an answer on June 15, 2026 at 8:03 pm

    First, I hope you do some sanitizing to avoid sql injection.

    Then you can at your choice :

    • not run the query if sanitizing parameter including a trim() is empty
    • have SELECT firstname, lastname FORM myTable WHERE ((lastname LIKE '" + parameter + "%') AND ''<>'" + parameter + "'"

    the second one being a bad practice from a performance point, and it would assume you’ve given up sanitizing (very bad)

    Also you should note that, in your sanitizing process, you will have to escape or remove special characters _ and %, see
    http://msdn.microsoft.com/en-us/library/ms179859(v=sql.105).aspx

    I you do not handle this, a non empty parameter equal to % will lead to a like '%%', which is equivalent to like '%'

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using this SQL query: Select * from table_name what happens if the name
Is this possible? Using SQL Server 2005....... SELECT * FROM Data0304 UNION SELECT *
I am trying to get the value of rows depending on the sql select
I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER
I'm using SQL Server 2005 and I'm trying to achieve something like this: I
I am trying to get information from an SQL database using python I was
I am trying to limit the following SQL statement. SELECT expense.*, transaction.* FROM expense
I'm using this SQL query to create an index: $query = CREATE INDEX id_index2
I am using this code to search data in SQL Server. But the result
I much prefer using this 'embedded' style inserts in a pl/sql block (opposed to

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.