-4

I am trying to make a Microsoft Access database that is connected to a view/form for a home project. To display the data on the form, I intend to query with inline SQL.

I have found examples online, but no real explanation, so I hope someone can explain the following:

1. What is the difference between these two

table.Countries.[CountryName]

table.Countries.CountryName

Thank you in advance

thesystem
  • 554
  • 1
  • 10
  • 31
  • 2
    1. no difference. 2. * is wildcard. – geeFlo Dec 11 '18 at 20:27
  • 1
    That asteric is a wildcard, meaning it will be pull all records where the field `CountryName` is essentially not blank. – dwirony Dec 11 '18 at 20:28
  • 1
    Possible duplicate of [\[\] brackets in sql statements](https://stackoverflow.com/questions/153861/brackets-in-sql-statements) Also VBA is irrelevant here. – JNevill Dec 11 '18 at 20:42

1 Answers1

1

The square brackets qualify the text within as a column name. They are required if someone, against recommendation, creates a column name the same as a reserved word. For example, if you have a column named Date, the following will error:

SELECT t.Date FROM Table1 t

In this case, you would need to qualify the column name with square brackets:

SELECT t.[Date] FROM Table1 t

It is HIGHLY recommended to just avoid using reserved words as column names. Additionally, if you want to alias a column name with spaces in the alias, square brackets are required:

SELECT t.MyDate AS [Invoice Date] FROM Table1 t

The * is the MS Access wildcard for the LIKE clause. It's worth noting that Microsoft SQL Server uses the % as the wildcard.

HardCode
  • 6,497
  • 4
  • 31
  • 54