从数据表中删除引号 [英] Remove quotation marks from data table

查看:87
本文介绍了从数据表中删除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Basic中有一个数据表,其中包含用引号括起来的数据行。



| 例子| 例子| 例子| 示例|



我理想情况下要删除引号,因为我目前还有一个复制在引号中的SQLBulkCopy。



如果有人能告诉我如何删除它们那就太棒了!

解决方案

假设你使用的是Microsoft SQL Server提到SQLBulkCopy。



要从已有数据中删除引号,请向数据库添加一个函数,然后使用该函数修复包含引号的列。如果数据尚未在SQL Server数据库中,那么您的VB .NET程序应该使用 String.Replace 方法在将新行插入数据库表之前删除引号正如VitorHugoGarcia上面的评论中所述。



向SQL Server添加新功能

  SET   ANSI_NULLS   ON  
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION RemoveQuotes

@ str varchar 800

RETURNS varchar 800
AS
BEGIN
声明 @ x int = 1;
声明 @ strTemp varchar 800 );
设置 @ strTemp = @ str;
WHILE @ x> 0
BEGIN
SELECT @ x = CHARINDEX( CHAR 34 ),< span class =code-sdkkeyword> @ strTemp , @ x
if @ x> 0
BEGIN
SELECT @ strTemp = STUFF(< span class =code-sdkkeyword> @ strTemp , @ x 1 ,< span class =code-string>' '
END
END
返回 @ strTemp
END





执行使用RemoveQuotes函数的UPDATE语句

 更新 YourTableName 
设置 col1 = RemoveQuotes(col1) ,COL2 = RemoveQuote(COL2),RemoveQuotes(COL3),COL2 = RemoveQuote(COL4)


I have a data table in Visual Basic which contains rows of data that are called enclosed in quotations.

| "example" | "example" | "example" | "example" |

I would ideally like to remove the quotation marks as I currently have a SQLBulkCopy that is copying in the quotations also.

If anyone could tell me how to remove these then that would be great!

解决方案

Assuming you are using Microsoft SQL Server since you mentioned SQLBulkCopy.

To remove quotes from an already existing data, add a function to the database then use that function to fixup the columns containing quotes. If the data is not yet in an SQL Server database, then your VB .NET program should use the String.Replace method to remove the quotes before inserting new rows into the database table as stated in VitorHugoGarcia's comment above.

Add a new function to your SQL Server

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION RemoveQuotes 
(
	@str varchar(800)
)
RETURNS varchar(800)
AS
BEGIN
Declare @x int=1;
Declare @strTemp varchar(800);
Set @strTemp=@str;
WHILE @x>0
BEGIN
	SELECT @x=CHARINDEX(CHAR(34),@strTemp,@x)
	if @x>0
	BEGIN
		SELECT @strTemp=STUFF(@strTemp,@x,1,'')		
	END
END
Return @strTemp
END



Execute an UPDATE statement using the RemoveQuotes function

Update YourTableName 
Set col1=RemoveQuotes(col1),col2=RemoveQuote(col2),RemoveQuotes(col3),col2=RemoveQuote(col4)


这篇关于从数据表中删除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆