Escape ampersand with SQL Server

ε祈祈猫儿з 提交于 2020-01-24 20:20:09

问题


I have this SQL-Server query

UPDATE qryPETEUR_frmPricingModel() SET G&A = '68442.0000' WHERE comp_id = '10004'

Which fails because Incorrect syntax near '&'

The query works when I change the field being edited to something without an ampersand, so I think the ampersand is the problem. Unfortunatly I am stuck having to use the use the field G&A and can't change it.

What can I do to get this query working. I think I have to escape the ampersand, but I can't figure out how. I have tried adding \ slash in front of it as well as adding ESCAPE '\' to the end of the query, but nothing worked.

I am also using Code Igniter if that helps.


回答1:


You don't escape field names. Put brackets around it:

UPDATE qryPETEUR_frmPricingModel()
SET [G&A] = '68442.0000'
WHERE comp_id = '10004'


来源:https://stackoverflow.com/questions/10820872/escape-ampersand-with-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!