重复删除 48 个字段中的引号

发布于 2025-01-08 15:12:24 字数 476 浏览 2 评论 0原文

下面的脚本在逐个字段的基础上工作,并删除每个条目开头和结尾的引号,但是如果您有超过 3 或 4 列,复制、粘贴更改到每个新列名称需要大量的时间时间。知道如何让它循环遍历每一列吗?

--Removing quotes back and front from fields where datetime_updated is not blank
UPDATE [Majestic].[dbo].hdiyouth_school_2
SET datetime_updated=left(right(cast(datetime_updated as nVarchar), 
    LEN(cast(datetime_updated as nVarchar))-1),
    LEN(cast(datetime_updated as nVarchar))-2)
WHERE datetime_updated IS NOT NULL AND datetime_updated LIKE '"%"'

This script below works on a field by field basis, and removes the quotes at the beginning and the end of every entry, BUT if you have more than 3 or 4 columns, copying, pasting changing to every new column name takes a huge amount of time. Any idea how to have this perhaps loop through every column?

--Removing quotes back and front from fields where datetime_updated is not blank
UPDATE [Majestic].[dbo].hdiyouth_school_2
SET datetime_updated=left(right(cast(datetime_updated as nVarchar), 
    LEN(cast(datetime_updated as nVarchar))-1),
    LEN(cast(datetime_updated as nVarchar))-2)
WHERE datetime_updated IS NOT NULL AND datetime_updated LIKE '"%"'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲娇萝莉攻 2025-01-15 15:12:24

您可以以类似于以下的方式为每列自动生成查询:

select 
'UPDATE [Majestic].[dbo].hdiyouth_school_2
SET ['+column_name+']=left(right(cast(datetime_updated as nVarchar), 
    LEN(cast(datetime_updated as nVarchar))-1),
    LEN(cast(datetime_updated as nVarchar))-2)
WHERE datetime_updated IS NOT NULL AND datetime_updated LIKE ''"%"'';'
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Employee' and TABLE_SCHEMA='HumanResources'

You can auto-generate a query for each column, in a manner similar to this:

select 
'UPDATE [Majestic].[dbo].hdiyouth_school_2
SET ['+column_name+']=left(right(cast(datetime_updated as nVarchar), 
    LEN(cast(datetime_updated as nVarchar))-1),
    LEN(cast(datetime_updated as nVarchar))-2)
WHERE datetime_updated IS NOT NULL AND datetime_updated LIKE ''"%"'';'
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Employee' and TABLE_SCHEMA='HumanResources'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文