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
相关文档:
这段时间看了关于在SQL server 中通过日志和时间点来恢复数据。也看了一些网上的例子,看如何通过日志来恢复数据。
前提条件:
数据库的故障恢复改为非简单模式,去掉自动关闭和自动收缩两个选项
&nbs ......
--> 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 ......
最近,工作的上需要处理一下项目中的极少量数据的重复问题。经过分析,结果发现是程序并发没有处理好而导致的。经过一番摸索,对数据库中的锁及程序的并发有了一点点小的心得。特写到此来与大家分享一下。
首先,我们来了解一下什么叫做锁。
......
asp衔接Mssql的办法及常见的差错
//第一种写法:
MM_conn_STRING = "Driver={SQL Server};server=(local);uid=sa;pwd=;database=infs;"
Set conn = Server.Createobject("ADODB.Connection")
conn.open MM_conn_STRING
SET RS=SERVER.CreateObject("ADOBD.recordset")
SQL="SELECT * from TABLE ORDER BY ID DESC"
R ......
MSSQL 如何实现 MySQL 的 limit 查询方式
不知为何,MSSQL 中没有 limit 这个极为重要的查询方式,熟悉 MySQL 的朋友都知道,MySQL 的 limit 对于实现分页和一些限制结果集的应用中非常方便。没有不要紧,我们可以用其他方法达到同样的目的,自己动手,丰衣足食!
语法:
Code:
SELECT * from
(
......