替换表达式格式xx-xx-xxxx_12345678

发布于 2025-02-05 17:54:35 字数 1024 浏览 3 评论 0 原文

标识符
31-03-2022_13636075
01-04-2022_13650262
04-04-04-2022_136663174
05-04-2022_13672025
xxxxx_
-
在某些
部分
值中
xx

删除(仅)“ xx- SSI中的列,但没有影响没有此格式的值?例如,“ 21-05-2022_12345678” =“ 12345678”,但我不希望它们受影响的其他值。这只是此列中许多行的示例,因此我只希望那些具有这种格式的人。

SELECT REVERSE(substring(REVERSE('09-03-2022_13481330'),0,CHARINDEX('_',REVERSE('09-03-2022_13481330'),0)))
结果
13481330

,但这也会影响其他值。此外,这是SSMS而不是SSIS中的,因为我不确定如何在SSIS代码中转换此表达式。

更新:SSIS中的校正代码如下:

(FINDSTRING(IDENTIFIER,"__-__-____[_]",1) == 1) ? SUBSTRING(IIDENTIFIER,12,LEN(IDENTIFIER) - 11) : IDENTIFIER
IDENTIFIER
31-03-2022_13636075
01-04-2022_13650262
04-04-2022_13663174
05-04-2022_13672025
20220099001
11614491_R
10781198
00000000000
11283627_P
11614491_R
-1

how can i remove (only) the "XX-XX-XXXXX_" Part in certain values of a column in SSIS but WITHOUT affecting values that doesn't have this format? For example "21-05-2022_12345678" = "12345678" but the other values i don't want them affected. This are just examples of many rows from this column so i want only the ones that have this format to be affected.

SELECT REVERSE(substring(REVERSE('09-03-2022_13481330'),0,CHARINDEX('_',REVERSE('09-03-2022_13481330'),0)))
result
13481330

but this also affects others values.Also this is in ssms not ssis because i am not sure how to transform this expression in ssis code.

Update : Corrected code in SSIS goes as following:

(FINDSTRING(IDENTIFIER,"__-__-____[_]",1) == 1) ? SUBSTRING(IIDENTIFIER,12,LEN(IDENTIFIER) - 11) : IDENTIFIER

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

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

发布评论

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

评论(1

妞丶爷亲个 2025-02-12 17:54:35

您可以访问SQL源吗?您可以通过使用喜欢的在SQL上进行此操作,并使用单个Char Wildcard _ 请参见下面的示例,

DECLARE @Value VARCHAR(50) = '09-03-2022_13481330'
SELECT CASE WHEN @Value LIKE '__-__-____[_]%' THEN 
SUBSTRING(@Value,12,LEN(@Value)-11) ELSE @Value END

请参见喜欢 并使用单个char通配符,

如果您无法访问源SQL更棘手,因为您可能需要在脚本任务中使用Regex,或者可能有一个可以应用的表达式

Do you have access to the SQL source? You can do this on the sql by using a LIKE and crafting a match pattern using the single char wildcard _ please see below example

DECLARE @Value VARCHAR(50) = '09-03-2022_13481330'
SELECT CASE WHEN @Value LIKE '__-__-____[_]%' THEN 
SUBSTRING(@Value,12,LEN(@Value)-11) ELSE @Value END

Please see the Microsoft Documentation on LIKE and using single char wildcards

If you don't have access to the source SQL it gets a bit more tricky as you might need to use regex in a script task or maybe there is a expression you can apply

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文