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表示降序排列
......
在VS中写SQL语句的时候,千万万千要小心再小心,比如 说 数据类型的匹配, 单引号(这个能把人迷死)
where 子句中可千万不能有空格(当查询条件为字符串的时候能把你弄疯,我弄这个的时候都疯了几次了,什么都对就是查不出来,调试了N遍才发现。)不行了,吃饭去,再不吃看见活人都想咬了。 ......
项目中需要根据课件名称按月统计出访问的情况,第一次我采用了最土的一种办法,使用循环,给sql传递年月两个参数,
for(var y=2009;y<=2010;y++){
for(var m=1;m<=12;m++){
// todo : SQL 查询
}
}
这样,统计2 ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......