sql把相同条件的列值合并在一起,并用“;”分隔

SELECT distinct TEMP.vch_number,TEMP.vch_code,vch_name=stuff((select ‘;‘+vch_name from TABLEB where (vch_number=TEMP.vch_number and vch_name<>‘‘ ) for xml path(‘‘)),1,1,‘‘) FROM #TBL_READ_NUMBER TEMP
时间: 2024-10-12 22:25:56

sql把相同条件的列值合并在一起,并用“;”分隔的相关文章

php 按列值合并数据

/* * PHP按值合并数组 * */ function my_array_merge(&$array1, &$array2) { $result = Array(); foreach($array1 as $key => &$value) { $result[$key] = array_merge($value, $array2[$key]); } return $result; }

ORACLE列值合并

select sfc,repair_index,listagg(method,'/') within group (order by sfc)as method from MES2_BYD_REPAIR_OPERATION where method is not null group by sfc,repair_index

sql分组统计多列值

select BQDM,sum(case when HFBZ='0' then 1 ELSE 0 end) bxschf,sum(case when HFBZ='1' then 1 ELSE 0 end) xschf,sum(case when HFBZ='2' then 1 ELSE 0 end) yschf,sum(case when HFBZ='3' then 1 ELSE 0 end) xxghffrom T_ZYBR_INFO group by BQDM

SQL判断如果一列值为null则取另一列值代替 isnull()

SELECT TOP 1000 [chClientCode] ,[nvcClientName] ,[chRegionCode] ,isnull(chUltimateHeadClientCode,[chClientCode]) as chUltimateHeadClientCode FROM [PwCMDM_V1].[Core].[tblClient] Define: isnull(expression,replacement_value)

SQL Server 强行Insert包含自增列值的记录

SET IDENTITY_INSERT 表 ON INSERT INTO 表 ([ID] ,[SequenceNumber] ,[EnumCode] ,[Description]) VALUES (6 ,1 ,'Empty' ,'Empty') SET IDENTITY_INSERT 表 OFF 此处ID为自增列 SQL Server 强行Insert包含自增列值的记录,布布扣,bubuko.com

SQL 重置自增列的值 批量处理

Declare @IdentityTable sysname, @IdentityColumn sysname, @TotalRows int, @i int, @Iden int, @Sql varchar(4000) SET NOCOUNT ON--标识列表Create Table #IDENTITY_Table(SeqID_int int identity(1,1), IDENTITY_TABLE sysname null,IDENTITY_COLUMN sysname null,IDEN

SQL将一个表中的某一列值全部插入到另一个表中

1.  SQL将一个表中的某一列值全部插入到另一个表中 插入的话: insert into a(col) select col from b; 更新的话: update a set col=select col from b where a.id=b.id; 判断表是否存在数据库中,存在就删除 if exists (select * from Sysobjects where name='temp') begin drop table temp end

sql 表中列值转成字符串

DECLARE @STR VARCHAR(8000)SELECT @STR=ISNULL(@STR+',','')+weixinuser FROM (SELECT DISTINCT weixinuser FROM v_sysbinduser)AS TSELECT @STR declare @output varchar(8000)select @output = coalesce(@output + ',' , '') + weixinuser from v_sysbinduserprint @

SQL练习之两个列值的交换

SELECT * FROM dbo.test2 现在我们将Province列值和Company列值互换,代码如下: UPDATE test2 SET Company=Province, Province=Company 这是第一种列值互换方式! 下面是第二种在部分数据库中有效的互换方式: UPDATE test2 SET Company=Company+Province, Province=Company-Province, Company=Company-Province; 这里的加减号可能有