Question

I'm unable to select from a table that contains & (ampersand). I'm querying the SQL Server database using VB.NET, the exception it throws is

incorrect syntax near '&'

Here's the code I'm using:

Using Com As New SqlCommand("SELECT * FROM Appointments&Results", Conn)
Using RDR = Com.ExecuteReader()
    If RDR.HasRows Then
        Do While RDR.Read
        'Get values here
        Loop
    End If
End Using
End Using

And here are queries that I've tried:

SELECT * FROM `Appointments&Results`
SELECT * FROM 'Appointments&Results'
SELECT * FROM `Appointments&&Results`
SELECT * FROM `Appointments&Results`

Any ideas?

Was it helpful?

Solution

SELECT * FROM [Appointments&Results]

That answers your question.

My question is, who in the world named the table with an ampersand (&)?!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top