SQL实现完全排列组合
---SQL实现完全排列组合
create function F_strSpit(@s varchar(200)) returns table
as
return(
select value=substring(@s,i,num)+substring(@s,num-1+j,1)
from (select num=number from spt_values where type='p' and number<len(@s) and number>0)TA,
(select i=number+1 from spt_values where type='p' and number<len(@s)-1)TB,
(select j=number+2 from spt_values where type='p' and number<len(@s)-1)TC
where num-1+j<=len(@s) and j>i )
declare @s varchar(200)
set @s='ABCE'
select * from dbo.F_strSpit(@s) order by len(value),value
/*
value
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AB
AC
AE
BC
BE
CE
ABC
ABE
BCE
ABCE
(所影响的行数为 10 行)
*/
drop function F_strSpit
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
清空日志:
dump transaction 库名 with no_log
截断日志:
backup log 库名 with no_log
压缩数据库:
dbcc shrinkdatabase (库名, 目标比率)
压缩数据库文件:
dbcc shrinkfile (文件名或ID, 目标大小)
文件名或ID可以通过系统表sysfiles查找,如果不指定目标大小SQL Server将最大限度的压缩数据库文件。
查看压 ......
SELECT * into newtable
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\aaaa.xls";User ID=Admin;Password=;Extended properties=Excel 11.0')...[Sheet1$]
/******* 导出到excel
exec master..xp_cmdshell 'bcp settledb.dbo.shanghu out c:\temp1.xls -c -q -s"gnetdata/gnetdata" - ......
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中 ......
table a(id, type):
id type
----------------------------------
1 1
2 1
3 &n ......