把一列数据拼接成一个字符串比较简单: declare @test varchar(500) set @test=''; select @test=@test+name+',' from person select @test 但是如果数据中有重复选项,想去掉重复的就比较绕弯了. ) set @test=''; select distinct @test=@test+name+',' from person select @test 加distinct是不行的,我在sql server 2008…
) SET @resultstr='' SELECT @resultstr=@resultstr+'|'+[BaseImage] FROM dbo.life_fc PRINT @resultstr 示例2 ),),),) SET @imgColleciton='' SELECT @citcode=BaseCityCode FROM dbo.life_fc SELECT @type= BaseTypeID FROM dbo.life_fc SELECT @imgColleciton=@imgCol…
SQLServer中查询的数字列前面补0返回指定长度的字符串: 如: 角本如下: /****** Script for SelectTopNRows command from SSMS ******/ SELECT TOP [ID] ,[SN] ,[Name] FROM [EduDB].[dbo].[TestTab] ',SN) from TestTab; )+CAST(SN AS varchar()),) AS 'SN' from TestTab; )),) as 'sn' from Test…
这次在开发中遇到,有列数不固定的情况.废话不多说,先上图,在上代码. 下面上JS代码 function SearchData() { var dYear = $("#DYear").val(); var beginWeek = $("#DSWeek").val(); var endWeek = $("#DEWeek").val(); var params = {}; params = CreateParamData(params, "d…