I have a dynamic sql statement that I want to fire off to SQL Server. The base of the query is in a variable called query:
<cfset query ="select
ParcelID,
LTRIM(IIF(AddNum IS NOT NULL, ' ' + AddNum, '') + IIF(AddDir IS NOT NULL, ' ' + AddDir, '') + ' ' + AddStreet + IIF(AddUnitNum IS NOT NULL, ' ' + AddUnitNum, '') + ' ' + AddCity + ', ' + AddState + ' ' + AddZip + IIF(AddZip4 IS NOT NULL, '-'+ AddZip4, '')) as Address
from PropertyParameters
where AddZip = '#URL.zip#'">
My problem is the areas where you see quote-space-quote plus field (ie. ' ' + AddNum), the single quote adds more single quotes, and sends the following to sql server:
select ParcelID,
LTRIM(IIF(AddNum IS NOT NULL, '' '' + AddNum, '''') + IIF(AddDir IS NOT NULL, '' '' + AddDir, '''') + '' '' + AddStreet + IIF(AddUnitNum IS NOT NULL, '' '' + AddUnitNum, '') + '' '' + AddCity + '', '' + AddState + '' '' + AddZip + IIF(AddZip4 IS NOT NULL, ''-''+ AddZip4, '')) as Address
from PropertyParameters
where AddZip = 20001 and Score > 70;
as you can see, the quotes are doubled and fails in sql server. How do I overcome this?
Thanks.
UPDATE 1: I tried escaping the quote according to coldfusion instructions ('' and "") and that still didn't work. Thanks