易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

MSSQL的Index也要优化。

在处理系统优化的时候,发现index使用不当的话,系统的性能不能很好发挥。
如:今天的发现的一个sql语句,经过分析,使用了2个index。但是2个index返回的记录在互相匹配过程中耗时最多。所以,即使SQL语句使用index,也不代表这个语句在性能上是很好的。 ......

MSSQL 实现 MySQL 的 limit 查询方式

MSSQL 如何实现 MySQL 的 limit 查询方式
不知为何,MSSQL 中没有 limit 这个极为重要的查询方式,熟悉 MySQL 的朋友都知道,MySQL 的 limit 对于实现分页和一些限制结果集的应用中非常方便。没有不要紧,我们可以用其他方法达到同样的目的,自己动手,丰衣足食!
语法:
Code:
SELECT * from
(
    ......

MSSQL全文检索

MSSQL全文检索 --1.打开数据库
use pubs
go
--2.打开全文索引支持
--execute sp_fulltext_database 'enable'
/*
(所影响的行数为 1 行)
(所影响的行数为 0 行)
(所影响的行数为 1 行)
*/ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号