Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 需要帮助从案例中删除功能吗_Loops_Tsql_Pattern Matching_Patindex - Fatal编程技术网

Loops 需要帮助从案例中删除功能吗

Loops 需要帮助从案例中删除功能吗,loops,tsql,pattern-matching,patindex,Loops,Tsql,Pattern Matching,Patindex,我有一种情况,我创建了脚本来选择公司环境中的数据。在这样做的过程中,我决定使用函数进行一些模式匹配,并在需要时剥离字符 然而,我们的一个客户不想让我们将他们的数据放在本地环境中,因此我现在需要对脚本进行处理,以便能够在他们的环境中运行——基本上意味着我需要删除函数,我很难思考如何移动这些东西来实现这一点 函数调用的一个示例是: SELECT .... CASE WHEN Prp = 'Key Cabinet' AND SerialNumber IS NOT NULL

我有一种情况,我创建了脚本来选择公司环境中的数据。在这样做的过程中,我决定使用函数进行一些模式匹配,并在需要时剥离字符

然而,我们的一个客户不想让我们将他们的数据放在本地环境中,因此我现在需要对脚本进行处理,以便能够在他们的环境中运行——基本上意味着我需要删除函数,我很难思考如何移动这些东西来实现这一点

函数调用的一个示例是:

SELECT ....
CASE WHEN Prp = 'Key Cabinet'
        AND SerialNumber IS NOT NULL
        AND dbo.fnRemoveNonNumericCharacters(SerialNumber) <> ''
     THEN dbo.fnRemoveNonNumericCharacters(SerialNumber)
....
INTO #EmpProperty
FROM ....
其中
@strText
是我要传递的
序列号

我可能会陷入分析瘫痪,因为我就是想不出一个好的方法来做到这一点。我不需要一个完整的解决方案,也许只是告诉我一个你知道会奏效的方向。让我知道你是否想要一些DDL/DML样本来处理这些东西

“序列号”值示例:
CA100(垃圾箱)
T110
101B

还有一些其他类型的值,比如所有文本或所有数字,但我们正在过滤掉它们。当前的模式匹配已经足够好了。

所以我想你的意思是你不能使用函数。。。因此,也许:

declare @table table (SomeCol varchar(4000))
insert into @table values
('1 ab2cdefghijk3lmnopqr4stuvwxyz5 6 !7@#$8%^&9*()-10_=11+[]{}12\|;:13></14? 15'),
('CA100 (Trash bins), T110, 101B')

;with cte as (
    select top (100) 
    N=row_number() over (order by @@spid) from sys.all_columns),

Final as (
    select SomeCol, Col
    from @table
        cross apply (
            select (select X + ''
            from (select N, substring(SomeCol, N, 1) X 
                  from cte 
                  where N<=datalength(SomeCol)) [1]
            where X between '0' and '9'
            order by N
            for xml path(''))
        ) Z (Col)
    where Z.Col is not NULL
)

select 
    SomeCol
    ,cast(Col as varchar) CleanCol  --change this to BIGINT if it isn't too large
from Final
declare@table表(SomeCol varchar(4000))
插入到@table值中

('1 ab2cdefghijk3lmnopqr4stuvwxyz5 6!7#$8%^&9*()-10 =11+[]{}12\:13>那一列是什么?你能给出一些数据示例吗?听起来不错@scsimon!我放了一些进去。
declare @table table (SomeCol varchar(4000))
insert into @table values
('1 ab2cdefghijk3lmnopqr4stuvwxyz5 6 !7@#$8%^&9*()-10_=11+[]{}12\|;:13></14? 15'),
('CA100 (Trash bins), T110, 101B')

;with cte as (
    select top (100) 
    N=row_number() over (order by @@spid) from sys.all_columns),

Final as (
    select SomeCol, Col
    from @table
        cross apply (
            select (select X + ''
            from (select N, substring(SomeCol, N, 1) X 
                  from cte 
                  where N<=datalength(SomeCol)) [1]
            where X between '0' and '9'
            order by N
            for xml path(''))
        ) Z (Col)
    where Z.Col is not NULL
)

select 
    SomeCol
    ,cast(Col as varchar) CleanCol  --change this to BIGINT if it isn't too large
from Final