Friday, March 9, 2012

Invalid column error

Hello all,
Does anyone see anything wrong with the sql query below


DECLARE @.BUILDINGLIST nvarchar(100)
SET @.BUILDINGLIST = 'ALABAMA'

DECLARE @.SQL nvarchar(1024)

SET @.SQL = 'SELECT id, CLOSED, building AS BUILDING FROM
requests WHERE building = (' + @.BUILDINGLIST + ')'

EXEC sp_executesql @.SQL

I keep on getting the following error:
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'ALABAMA'.

Thanks in advance.
Richard M.you need an xtra set of quotations.


SET @.SQL = 'SELECT [id], CLOSED, building AS BUILDING FROM
requests WHERE building = ('' + @.BUILDINGLIST + '')'

hth|||actually... one more than that.

(''' + @.BuildingList + ''')'

or SET @.BUILDINGLIST = '' + @.BUILDINGLIST + ''

Then run the original way.

'' would cancel into one '.

No comments:

Post a Comment