views:

70

answers:

2

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

+2  A: 

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.

uriDium
doh! thanks man.. tired eyes..
phill
Don't worry. Do it all the time. At least you copy-pasted and didn't rewrite the query but correctly this time and have us all scratching our heads :)
uriDium
A: 

use "current" join syntax:

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