phill
phill

Reputation: 13844

tsql : how do you query with dashes in column names?

I have the query

select * from products p, products_temp t 
where p.ManufacturerPartNumber = t.[INV-PRICE-VENDOR-PART]

where the column names have dashes in them which SQL Server 2005 seems to automatically add brackets to. What is the correct way of accessing this in a query? I've tried with brackets and without the brackets and just end up with errors.

the error I get from sql mgmt studio is

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'where'.

thanks in advance

Upvotes: 0

Views: 3792

Answers (2)

KM.
KM.

Reputation: 103587

use "current" join syntax:

SELECT
    *
    from products                 p
        INNER JOIN products_temp  t  ON p.ManufacturerPartNumber = t.[INV-PRICE-VENDOR-PART]

Upvotes: 0

uriDium
uriDium

Reputation: 13420

that is because you have repeated WHERE twice in your statement. Got nothing to do with the square brackets which you will need because of the dashes.

Upvotes: 3

Related Questions