If you need to query all People from Person table with FirstName start with A, you can easily query like below,
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,
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,
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.
Have you ever thought, what if your table name
1. Is exactly as of SQL Server keyword
2. Is having space in between like Student Fav Actor
If you go ahead and query against table Student Fav Actor like below, most likely you will get error message as below,
There may me one more scenario where table name is something like FROM. If you query in usual way, obviously you will be getting expected error message.
So how to query table named [However this is wrong practice to put spaces and use SQL Server keyword as table name] like above?
Very simple is the solution, put table name in square brackets.
You might encounter columns name of table are having spaces or named as keywords. In that case also you need to apply square bracket with that particular column name to work with.