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

SQL Select N to M Records (single Table)

取表里n到m条纪录的几种方法:
1. 只需要查询前M条数据(0 to M),
1.1 使用 top(M) 方法:
select top(3) * from [tablename]
 
1.2 使用 set rowcount 方法:
http://msdn.microsoft.com/zh-cn/library/ms188774(SQL.90).aspx
set rowcount M
select * from [tablename]
set rowcount 0
权限 要求具有 public 角色成员资格。
要执行set rowcount 0, 否则影响以后查询等.
 
 
2.查询N到M条数据(N to M),
2.1  表里面有标识列
2.1.1
select top (M-N+1) * from [tablename] where [columnname] not in (select top (N) [columnname] from [tablename])
 
2.1.2  逆序显示
select top N * from (select top M * from [tablename] order by [columnname]) temp order by [columnname] desc
 
2.1.3 顺序显示
select * from (select top N * from (select top M * from [tablename] order by [columnname]) temp1 order by [columnname] desc) temp2 order by [columnname]
 
 
2.2 表里有identity属性
select * from [tablename] where identitycol between N and M
 
如[columnname]为identity属性,则可以写成:
select * from [tablename] where [columnname] between N and M
 
2.3 表里面有标识列, 利用临时表
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
    drop table [temptable]
end
select top M * into [temptable] from [tablename] order by [columnname]
set rowcount N
select * from [temptable] order by [columnname] desc
set rowcount 0
drop table [temptable] 
 
2.4 如果tablename里没有其他identity列,那么:
exec sp_dboption [DataBaseName] ,'select into/bulkcopy',true
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
    drop table temptable
end
select identity(int) id0,* into [temptable] from [tablename]
select * from temp where id0 >= N and id0 <= M
drop table temptable 
 
如果你在执行select identity(int) id0,* into [temp


相关文档:

oracle数据库字段类型及其与Java.sql.Types的对应

字符类型:
CHAR(size):固定长度字符串,最大长度2000 bytes
VARCHAR2(size):可变长度的字符串,最大长度4000 bytes,可做索引的最大长度749
NCHAR(size):根据字符集而定的固定长度字符串,最大长度2000 bytes
NVARCHAR2(size):根据字符集而定的可变长度字符串,最大长度4000 byte
LONG:变长的字符串,最大长度限 ......

mysql 一条sql语句update更新两个表

你写过一条sql语句来修改两个表的数据吗?
UPDATE test.table1 t1,test.table2 t2 SET t1.aa='a',t1.bb='b',t2.cc='c',WHERE t1.u_id=t2.u_id AND t1.u_id='1'  ;
table1的u_id和table2的u_id是主外键关系 ......

Sql server的odbc,ado,ado.net连接串.

应用程序通过odbc,ado或ado.net与sql server连接,无论通过那种方式进行连接,每一种连接方式,首先要设置的是连接串。以下就说说几种方式的连接串的设置:
先说说odbc连接,odbc全称为开放式数据库连接,是微软最早发布的数据库连接方式。连接串格式如下:driver={sql server};server=服务器安全名;uid=用户名;pwd=密码;databa ......

经典SQL语句

1,SELECT *,CASE OrderStatus WHEN 1 THEN '未处理' when 2 THEN '锁定' when
3 THEN '已出票' ELSE '过期' END
from  dbo.T_OrderItem
2,
SELECT *,CAST(ROUND(CAST (HostWin AS FLOAT)/(HostWin+HostDraw+HostBear),2)*100 AS varchar)+'%' AS HostWinRate,
        & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号