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

SQl SERVER 2000 遍历表中数据的方法

方法一:使用游标
declare @ProductName nvarchar(50)
declare pcurr cursor for select ProductName from Products
open pcurr
fetch next from pcurr into @ProductName
while (@@fetch_status = 0)
begin
print (@ProductName)
fetch next from pcurr into @ProductName
end
close pcurr
deallocate pcurr
此方法适用所有情况,对标结构没有特殊要求。
方法二:使用循环
declare @ProductName nvarchar(50)
declare @ProductID int
select @ProductID=min(ProductID) from Products
while @ProductID is not null
begin
select @ProductName=ProductName from Products where
ProductID=@ProductID
print(@ProductName);
select @ProductID=min(ProductID) from Products where
ProductID>@ProductID
end
此方法适用于表带有自动增加标识的字段


相关文档:

oracle sql优化之多表连接优化


Use equality first.
使用等连接
Use range operators only where equality does not apply.
只有在等连接不可用的情况下事由区间连接
Avoid use of negatives in the form of !=
or NOT.
避免使用 != 或者 not
Avoid LIKE pattern matching.
避免使用 LIKE匹配
Try to retrieve specific rows and in small n ......

计算年资的SQL语句

1.bzscs(沙虫 我爱小美)用函數的好辦法:
CREATE    function [dbo].[calc_date](@time smalldatetime,@now smalldatetime)
returns nvarchar(10)
as
begin
declare @year int,@month int,@day int
select @year = datediff(yy,@time,@now)
if  (month(@now)=month(@time)) and (day ......

SQL分页查询

/*第几页必须大于1
select top 每页数量 * id
 from @t a
 where id not in
 (select top (第几页-1)*每页数量 id
  from @t b
 )
*/
declare @lcSqlCommand nvarchar(100)
declare @t table (id int IDENTITY,orderDate datetime)
insert into @t
 select orderDate
&nb ......

SQL 2K 数据类型 (转)

(转载)SQL 2K 数据类型 
(1)char、varchar、text和nchar、nvarchar、ntext
char和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是变长字符数据。所谓定长就是长度固定的,当输入的数据长度没有达到指定的长度时将自动以英文空格在其后面填充,使长度达到相应的长度;而变长字符数据 ......

sql学习进行时

这两天都没有好好学习,今天终于算投入了些,由于课程的关系,我的sql也是同vb一起学习的。虽然知道贪多嚼不烂,可是按照实际情况,我完全没有理由抛弃sql的。
最近都把时间投入到vb和面向对象中,sql今天好好复习了下,从create database 开始,create table,alter table , add constraint   …&h ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号