zoukankan      html  css  js  c++  java
  • 行字段值拼接成字符串

    效果:
    SizeBatchNoSizingDyeBatchs
    SZ1281656B2081036/B2081037/B2081042
     1 WITH    SizingJob ( SizeBatchNo, BatchNo )
     2           AS ( SELECT   b.SizeBatchNo ,
     3                         b.BatchNo
     4                FROM     WVMDB.dbo.wvSizingBatchInfo a WITH ( NOLOCK )
     5                         LEFT JOIN ydmdb.dbo.ydbeambatchno_sizing b WITH ( NOLOCK ) ON a.Sizing_Batch_NO = b.SizeBatchNo
     6                WHERE    a.End_Time IS NULL
     7              )
     8     SELECT  SizeBatchNo ,
     9             CASE WHEN LEN(SizingDyeBatchs) > 0
    10                  THEN STUFF(SizingDyeBatchs, LEN(SizingDyeBatchs), 1'')
    11                  ELSE ''
    12             END AS SizingDyeBatchs
    13     FROM    ( SELECT DISTINCT
    14                         SizeBatchNo
    15               FROM      SizingJob
    16             ) a
    17             CROSS APPLY ( SELECT    SizingDyeBatchs = ( SELECT
    18                                                               BatchNo + '/'
    19                                                         FROM  SizingJob
    20                                                         WHERE SizeBatchNo = A.SizeBatchNo
    21                           FOR       XML PATH('') ,
    22                                         TYPE
    23             ).value('/''nvarchar(max)')
    24


     1 WITH    SizingJob ( SizeBatchNo, BatchNo )
     2           AS ( SELECT   b.SizeBatchNo ,
     3                         b.BatchNo
     4                FROM     WVMDB.dbo.wvSizingBatchInfo a WITH ( NOLOCK )
     5                         LEFT JOIN ydmdb.dbo.ydbeambatchno_sizing b WITH ( NOLOCK ) ON a.Sizing_Batch_NO = b.SizeBatchNo
     6                WHERE    a.End_Time IS NULL
     7              )
     8     SELECT  SizeBatchNo ,
     9             CASE WHEN LEN(SizingDyeBatchs) > 0
    10                  THEN STUFF(SizingDyeBatchs, LEN(SizingDyeBatchs), 1'')
    11                  ELSE ''
    12             END AS SizingDyeBatchs
    13     FROM    ( SELECT DISTINCT
    14                         SizeBatchNo
    15               FROM      SizingJob
    16             ) a
    17             CROSS APPLY ( SELECT    SizingDyeBatchs = ( SELECT
    18                                                               BatchNo + '/'
    19                                                         FROM  SizingJob
    20                                                         WHERE SizeBatchNo = A.SizeBatchNo
    21                           FOR       XML PATH('') ,
    22                                         TYPE
    23             ).value('/''nvarchar(max)')
    24                         ) b

  • 相关阅读:
    Geogebra指令
    大表修改表结构
    mongodb获取配置参数getParameter
    mysql的binlog增量日志解析,提供增量数据订阅和消费
    chaosblade-exec-os项目的burnio.go文件解读
    mysql的where条件中的字段不要加函数
    mysql释放大表空间的正确之道
    mysql服务器问题
    purge binary logs to 'mysql-bin.039790';
    golang操作mysql数据库的规范
  • 原文地址:https://www.cnblogs.com/yooplmqj/p/2696869.html
Copyright © 2011-2022 走看看