SQL Server tip : Query a range of characters ?

If you need to query all People from Person table with FirstName start with A, you can easily query like below,

clip_image002

What if you want to list all the people from person table with first name start with A and B? You can combined Like operator with OR and query like below,

clip_image003

But imagine scenario where you need to query all the People with FirstName start with A to M. How will you do that?

Solution is you need to put like operator in the square bracket as below,

clip_image005

If you modify one little thing in above query and replace like operator with equal operator , you will get no error message however you will get no rows returned as well.

One thought on “SQL Server tip : Query a range of characters ?

  1. Pingback: Monthly Report July 2011: Total Posts 16 « debug mode……

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s