SQL Server 2005 CTE的用法
if object_id('[tb]') is not null
drop table [tb]
go
create table [tb]([id] int,[col1] varchar(8),[col2] int)
insert [tb]
select 1,'河北省',0 union all
select 2,'邢台市',1 union all
select 3,'石家庄市',1 union all
select 4,'张家口市',1 union all
select 5,'南宫',2 union all
select 6,'坝上',4 union all
select 7,'任县',2 union all
select 8,'清河',2 union all
select 9,'河南省',0 union all
select 10,'新乡市',9 union all
select 11,'aaa',10 union all
select 12,'bbb',10
;with t as(
select * from [tb] where col1='河北省' union all select a.* from [tb] a ,t where a.col2=t.id
)
select * from t
相关文档:
例子: int id = Convert.ToInt32(replace((Request.QueryString["id"]), ""));
public static string replace(string str, string str2)
{
str = str.Replace(";", str2);
str = ......
今天练习在JSP页面中实现分页效果,在查询语句方面牵扯到了top的用法。简要做一下总结:
为实现类似top的功能,我们在SQL Server中和MySQL中使用到的SQL语句是不同的。
1、在SQL Server中,我们使用 select top N * ......
之前偶然逛网页的时候看到的,详细的网址忘记copy过来了,真是抱歉。觉得简单易懂,所以转了,嘻嘻
有关分页 SQL 的资料很多,有的使用存储过程,有的使用游标。本人不喜欢使用游标,我觉得它耗资、效率低;使用存储过程是个不错的选择,因为存储过程是经过预编译的,执行效率高,也更灵活。先看看单条 SQL 语句的分页 SQL ......
--查询现在日期,只要年月日
select convert(varchar(10),getDate(),120)
--查询现在日期,只要时分秒
select convert(varchar(8),getDate(),8)
Convert函数的一些说明,以下资料来源于网络
不带世纪数位 (yy)
带世纪数位 (yyyy)
标准
输入 ......
http://www.cnblogs.com/Mainz/archive/2008/12/20/1358897.html
什么情况下使用表变量?什么情况下使用临时表?
表变量:
DECLARE @tb table(id int identity(1,1), name varchar(100))
INSERT @tb
SELECT id, name
from mytable
WHERE name like ‘zhang%&rsquo ......