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
´Ë·½·¨ÊÊÓÃÓÚ±í´øÓÐ×Ô¶¯Ôö¼Ó±êʶµÄ×Ö¶Î
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......
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 ......
/*µÚ¼¸Ò³±ØÐë´óÓÚ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 structured query language
--DML--Data Manipulation Language--Êý¾Ý²Ù×÷ÓïÑÔ
query information (SELECT),
add new rows (INSERT),
modify existing rows (UPDATE),
delete existing rows (DELETE),
perform a conditional update or insert operation (MERGE),
see an execution plan of SQL (EXPLA ......