在sql中插入单引号

时间:2015-11-15 20:49:56

标签: sql sql-server-2008 sql-update sql-insert

我想在现有表格的AlertSQL列中插入“exec e_Report.dbo.FTX_FA_Aging_Report_sp'FACloedAgingReport'”。

我的更新脚本将如何?

我的更新脚本如下:

update dbo.F_ALERT
    set AlertSQL= 'exec e_Report.dbo.FTX_FA_Aging_Report_sp '''FACloedAgingReport''
        where AlertID=9330 

有些人如何不给我预期的结果。 在此先感谢!!

2 个答案:

答案 0 :(得分:0)

您需要更多报价和内容:

update dbo.F_ALERT
    set AlertSQL= 'exec e_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReport'''
        where AlertID = 9330 ;

这有点令人困惑,但''''是一个带有单引号的字符串。两个单引号一起是单个引号。因此:

'exec e_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReport'''
^ starts a string
------------------------------------------^ two quotes are single quote in the string
--------------------------------------------------------------^ two quotes are single quote in the string and then one more to end the string itself

答案 1 :(得分:0)

检查您的报价定位。在引用的字符串的任何一端都需要一对单引号,以及整个查询的引号。

'exec ee_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReportSee'''

目前你有三个前和后两个,根据戈登的回答它应该是另一种方式。

请参阅https://support.microsoft.com/en-us/kb/178070