sql server - how to stop coldfusion from adding single quotes in string -
this question has answer here:
i have dynamic sql statement want fire off sql server. base of query in variable called query:
<cfset query ="select parcelid, ltrim(iif(addnum not null, ' ' + addnum, '') + iif(adddir not null, ' ' + adddir, '') + ' ' + addstreet + iif(addunitnum not null, ' ' + addunitnum, '') + ' ' + addcity + ', ' + addstate + ' ' + addzip + iif(addzip4 not null, '-'+ addzip4, '')) address propertyparameters addzip = '#url.zip#'">
my problem areas see quote-space-quote plus field (ie. ' ' + addnum), single quote adds more single quotes, , sends following sql server:
select parcelid, ltrim(iif(addnum not null, '' '' + addnum, '''') + iif(adddir not null, '' '' + adddir, '''') + '' '' + addstreet + iif(addunitnum not null, '' '' + addunitnum, '') + '' '' + addcity + '', '' + addstate + '' '' + addzip + iif(addzip4 not null, ''-''+ addzip4, '')) address propertyparameters addzip = 20001 , score > 70;
as can see, quotes doubled , fails in sql server. how overcome this?
thanks.
update 1: tried escaping quote according coldfusion instructions ('' , "") , still didn't work. thanks
you sql query can simplified using following query isnull() function:
select parcelid ,ltrim( isnull(' ' + addnum , '') + isnull(' ' + adddir , '') + ' ' + addstreet + isnull(' ' + addunitnum, '') + ' ' + addcity + ', ' + addstate + ' ' + addzip + isnull('-'+ addzip4, '') ) address propertyparameters addzip = '#url.zip#
to escape single quotes need use preservesinglequotes()
function.
<cfquery ...>#preservesinglequotes(query)#</cfquery>
Comments
Post a Comment