mssql 列内数据横向连接,用逗号分割。
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[temp_Table]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[temp_Table]
GO
CREATE TABLE [dbo].[temp_Table] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[productname] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
insert into temp_table select column from table
declare @i int,@c int,@string varchar(5000),@j varchar(5000)
DECLARE @SQLString NVARCHAR(5000)
select @SQLString=N'select @c = count(*) from temp_table'
execute sp_executesql @sqlstring,
N'@c int output',
@c=@c output
set @i=1
set @string=''
while @i<=@c
begin
select @SQLString=N'select @j = productname from temp_table where id = '+cast(@i as varchar(5))
execute sp_executesql @sqlstring,
N'@j varchar(5000) output',
@j=@j output
select @string =@string + @j + ','
select @i=@i+1
end
select substring(@string,0,len(@string)-1)
drop table temp_table
相关文档:
--> Title : varbinary转换成字符串
--> Author : wufeng4552
--> Date : 2009-12-15
declare @s varchar(20),@bin varbinary(1000)
select @s='www.CSDN.net',@bin=cast(@s as varbinary(1000))
declare @re varchar(1000),@i int
select @re='',@i=datalength(@bin)
while @i>0
&n ......
SQL
insert into table_name(colum1,colum2)
select colum1,colum2
from opendatasource('sqloledb','data source=服务器名;user id=用户名 ;password=密码 ').database_name.dbo.table_name
如执行出现以下错误”sql server 阻止了对组件 \'ad hoc distributed queries\' 的访问&l ......
最近,工作的上需要处理一下项目中的极少量数据的重复问题。经过分析,结果发现是程序并发没有处理好而导致的。经过一番摸索,对数据库中的锁及程序的并发有了一点点小的心得。特写到此来与大家分享一下。
首先,我们来了解一下什么叫做锁。
......
在处理系统优化的时候,发现index使用不当的话,系统的性能不能很好发挥。
如:今天的发现的一个sql语句,经过分析,使用了2个index。但是2个index返回的记录在互相匹配过程中耗时最多。所以,即使SQL语句使用index,也不代表这个语句在性能上是很好的。 ......
1、SQL2000中一表有一日期型字段BirthDay,记录出生日期,想每年在本日生日前15天,将其过滤出来,怎么写Where条件?:
select out_date from sales_out_head_tab where (DATEDIFF(day,DATEADD(year ,year(getdate())-year(out_date) ,out_date )
,getdate()) BETWEEN -15 and 0 ) order by out_date ......