2015-11-15 158 views
2

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

我的更新脚本将如何?

我的更新脚本如下:

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

一些如何它不是给我预期的结果。 在此先感谢!

+0

哪个RDBMS是这样的?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –

+0

@marc_s sql server 2008 – sony921

回答

0

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

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

目前你有三个之前和两个之后,它应该是相反的戈登的答案。

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

+0

您是否在sql server 2008上试过它(如问题已标记)? – Arvo

+0

答案写入时没有标记问题 – QuantumTiger

+0

现在已编辑答案以反映SQl 2008 – QuantumTiger

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