简体   繁体   English

更新表列以删除SQL Server中不需要的双引号

[英]Update table column for removing unwanted double quotes in SQL Server

I want to update table entries simultaneously for all columns in one go. 我想一次更新所有列的表条目。

Suppose in the table, there is one column EmployeeName with entries like "SAM", "Jhon" and so on... 假设在该表中,有一列EmployeeName带有条目,例如“ SAM”,“ Jhon”等等。

I need all this entries under its column should appear like SAM , Jhon only... Double quotes should not be there, please provide me query for the scenario. 我需要在其列下的所有这些条目都应显示为SAM ,仅Jhon …不应在双引号中出现,请向我查询该情况。

Thanks in advance 提前致谢

Use Replace Function as next:- 接下来使用Replace功能:-

update TableName
set columnName= REPLACE(columnName,'"','')

Demo :- 演示 :-

Create table #Dummy (col varchar(100))

insert into #Dummy values ('"SAM", "Jhon", "Smith"')

update #Dummy
set col = REPLACE(col,'"','')


select *  from #Dummy

Result:- 结果:-

SAM, Jhon, Smith
update table1 set column1 = case 
   when column1 = 'entity1' then 'entity2'
   when column1 like '%entity3%' then 'entity4'
   else 'entity5'
end

To remove left-most quote: 删除最左边的报价:

UPDATE MyTable
SET EmployeeName = SUBSTRING(EmployeeName, 2, LEN(EmployeeName))
WHERE LEFT(EmployeeName, 1) = '"'

To remove right-most quote: 删除最右边的报价:

UPDATE MyTable
SET EmployeeName = SUBSTRING(EmployeeName, 1, LEN(EmployeeName)-1)
WHERE RIGHT(EmployeeName, 1) = '"' 

Or else you can also use a simpler way to remove all the quotes at once. 否则,您也可以使用更简单的方法一次删除所有引号。

update MyTable set EmployeeName = replace(EmployeeName,'"','')

Why not try the Replace function. 为什么不尝试Replace功能。

Syntax: REPLACE ( string_expression , string_pattern , string_replacement ) 语法: REPLACE ( string_expression , string_pattern , string_replacement )

If your table consist the data with double quote in the column, you need to update the table with the following query; 如果您的表包含该列中带有双引号的数据,则需要使用以下查询更新该表;

Update <tablename>
Set <columnName> = REPLACE(<columnName>,'"','')
where <ColumnWithUniqueVale> = <something>

eg Replace(EmployeeName,'"','') 例如Replace(EmployeeName,'"','')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM