我想用两个单引号替换一个单引号我要替换' - > ''像这样

时间:2016-01-28 08:03:19

标签: sql-server

我想用两个单引号替换一个单引号我要替换' - > ''像这样 查询:

UPDATE UniqueProds
SET OtherInvoiceName = REPLACE(@otherInvoiceName, '', '''')
WHERE HnyProdid = @ProductID
    AND attid IS NULL OR attid = ''
    AND AcInvoice = REPLACE(@AcInvoiceName, '', '''')

2 个答案:

答案 0 :(得分:2)

对于匹配部分,您需要一个单引号来启动字符串,另外两个用于在字符串中嵌入一个单引号,以及一个最终单引号来关闭字符串。对于替换部件,如果要将单引号替换为两个相邻的单引号,则需要另外两个单引号。因此,假设语法的其余部分是OK:

update  UniqueProds 
set  OtherInvoiceName=REPLACE(@otherInvoiceName,'''','''''') 
where HnyProdid=@ProductID and attid is null or attid='' and
      AcInvoice=REPLACE(@AcInvoiceName, '''', '''''')

如果您的意思是用单引号''替换单引号",那么很明显,答案会有所改变 - 匹配是相同但是更换更简单。

update  UniqueProds 
set  OtherInvoiceName=REPLACE(@otherInvoiceName,'''','"') 
where HnyProdid=@ProductID and attid is null or attid='' and
      AcInvoice=REPLACE(@AcInvoiceName, '''', '"')

答案 1 :(得分:0)

AcInvoicName = txtAcInvoice.Text.Split('_')[1].ToString().Replace("'","''");