Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
Sql server 2008 SQL Server:字段长度控制问题_Sql Server 2008_Data Warehouse_Varchar - Fatal编程技术网

Sql server 2008 SQL Server:字段长度控制问题

Sql server 2008 SQL Server:字段长度控制问题,sql-server-2008,data-warehouse,varchar,Sql Server 2008,Data Warehouse,Varchar,SQL Server 2008中的字符串长度控制面临一个大问题 简要回顾一下我们的系统: 在SQL Server环境中使用大容量插入,从*.txt文件分号作为分隔符导入持久暂存区域中的数据; PSA表中所有列均为varcharMAX; 使用基于具有多个where条件的select的insert语句进行清理操作。 我们处理的问题是关于单个列的类型和长度,事实上,在数据仓库级别,它必须是数字的,并且其长度不得超过13位 选择选项如下所示: select cast(LTRIM(RTRIM(data_g

SQL Server 2008中的字符串长度控制面临一个大问题

简要回顾一下我们的系统:

在SQL Server环境中使用大容量插入,从*.txt文件分号作为分隔符导入持久暂存区域中的数据; PSA表中所有列均为varcharMAX; 使用基于具有多个where条件的select的insert语句进行清理操作。 我们处理的问题是关于单个列的类型和长度,事实上,在数据仓库级别,它必须是数字的,并且其长度不得超过13位

选择选项如下所示:

select cast(LTRIM(RTRIM(data_giacenza)) as numeric), 
                        LTRIM(RTRIM(codice_socio)), 
                        LTRIM(RTRIM(codice_gln)), 
                        LTRIM(RTRIM(tipo_gln)), 
                        LTRIM(RTRIM(codice_articolo_socio)), 
                        LTRIM(RTRIM(codice_ean_prodotto)), 
                        LTRIM(RTRIM(codice_ecat_prodotto)), 
                        LTRIM(RTRIM(famiglia)), 
                        LTRIM(RTRIM(marca)),
                        LTRIM(RTRIM(classificazione_liv_1)), 
                        LTRIM(RTRIM(classificazione_liv_2)),
                        LTRIM(RTRIM(classificazione_liv_3)), 
                        LTRIM(RTRIM(classificazione_liv_4)), 
                        LTRIM(RTRIM(modello)), 
                        LTRIM(RTRIM(descrizione_articolo)), 
                        cast(LTRIM(RTRIM(giacenza)) as numeric),
                        cast(LTRIM(RTRIM(acquistato)) as numeric), 'X' FROM psa_stock a
                          where EXISTS 
                          ( 
                          SELECT 0 
                          FROM(
                                SELECT 
                                            data_giacenza
                                           ,codice_socio
                                                 ,codice_gln
                                                 ,codice_articolo_socio
                                                 FROM psa_stock 
            where
                        LEN(LTRIM(RTRIM(data_giacenza))) = 8 and LEN(LTRIM(RTRIM(codice_socio))) = 3
                  and LEN(LTRIM(RTRIM(codice_gln))) = 13 and LEN(LTRIM(RTRIM(tipo_gln))) = 3 
                  and LEN(LTRIM(RTRIM(codice_articolo_socio))) <= 15 
                  and (LEN(LTRIM(RTRIM(codice_ean_prodotto))) <= 13 or LEN(ISNULL(codice_ean_prodotto, '')) = 0) 
                  and (LEN(LTRIM(RTRIM(codice_ecat_prodotto))) = 9 or LEN(ISNULL(codice_ecat_prodotto, '')) = 0)
                  and LEN(LTRIM(RTRIM(famiglia))) = 2
                  and (LEN(LTRIM(RTRIM(marca))) <= 20 or LEN(ISNULL(marca, '')) = 0)
                  and (LEN(LTRIM(RTRIM(modello))) <= 30 or LEN(ISNULL(modello, '')) = 0)
                  and (LEN(LTRIM(RTRIM(descrizione_articolo))) <= 50 or LEN(ISNULL(descrizione_articolo, '')) = 0)
                  and LEN(LTRIM(RTRIM(giacenza))) <= 5
                  and LEN(LTRIM(RTRIM(acquistato))) <= 5 
                  and (LEN(LTRIM(RTRIM(classificazione_liv_1))) <= 15 or LEN(ISNULL(classificazione_liv_1, '')) = 0)
                  and (LEN(LTRIM(RTRIM(classificazione_liv_2))) <= 15 or LEN(ISNULL(classificazione_liv_2, '')) = 0)
                  and (LEN(LTRIM(RTRIM(classificazione_liv_3))) <= 15 or LEN(ISNULL(classificazione_liv_3, '')) = 0)
                  and (LEN(LTRIM(RTRIM(classificazione_liv_4))) <= 15 or LEN(ISNULL(classificazione_liv_4, '')) = 0)
                  and ISNUMERIC(ltrim(rtrim(REPLACE(data_giacenza, ' ', '')))) = 1 
                  and ISNUMERIC(ltrim(rtrim(REPLACE(codice_gln, ' ', '')))) = 1 
                  and ISNUMERIC(LTRIM(RTRIM(REPLACE(giacenza, ' ', '')))) = 1 and charindex(',', giacenza) = 0
                  and ISNUMERIC(LTRIM(RTRIM(REPLACE(acquistato, ' ', '')))) = 1 
                  and ISNUMERIC(ltrim(rtrim(REPLACE(codice_ean_prodotto, ' ', '')))) = 1
                  and ISNUMERIC(ltrim(rtrim(REPLACE(codice_ecat_prodotto, ' ', '')))) = 1
                  and codice_socio in (select codice_socio from ana_socio)
                  and tipo_gln in (select tipo from ana_gln)
                  and codice_gln in (select codice_gln from dw_key_gln)
                  group by 
               data_giacenza
              ,codice_socio
                  ,codice_gln
                  ,codice_articolo_socio
                             having COUNT (*) = 1
                  ) b
          where 
                a.data_giacenza = b.data_giacenza and
                a.codice_articolo_socio = b.codice_articolo_socio and
                    a.codice_socio = b.codice_socio and
                    a.codice_gln = b.codice_gln)
临界域是codice_ean_prodotto

实际上,它也可以考虑值为SeaGAT7636490026751、NE2000、03039、NE200、000、2168,它们不是数字的,第一个是重叠的最大维数。 结果,insert语句返回

二进制数据的字符串将被截断

错误,插入失败

提前谢谢!我期待你的帮助


Enrico

您是否尝试过执行该查询,并将codice_ean_prodotto='ne200000309'添加到where子句中?确保这些都是给您带来问题的实际字段。如果select返回带有where子句的行,则逻辑有问题

我倾向于在EXISTS子查询中使用having COUNT*=1子句—这些特定键可能有多个记录吗?只要你的PK由4个字段组成,即data_giacenza、codice_articolo_Social、codice_Social、codice_gln,你就根本不需要GROUP BY和HANG子句。如果你没有加入你的主键,它可能是罪魁祸首


但是,如果不查看您的数据模型,很难判断。

我发现了问题所在。 在内部选择中,我们从选择中排除了所有不遵守格式约束和重复count*=1的记录,只提取目标表的PK。 但是,当使用PK进行选择时,我们还检索那些重复的记录,但这些记录被格式约束排除,导致插入由于维度问题而出错

现在我将步骤分为:

重复查找和删除 带格式约束的选择 它起作用了