第一篇學習筆記
初學
儲存過程
USE [database]
GO/****** Object: StoredProcedure [dbo].[GetTodaySupply] Script Date: 03/16/2018 17:43:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
ALTER procedure [dbo].[GetTodaySupply]
@databegin datetime,
@dataend datetime
as
begin
create table #TabId
(
PrinterId int not null primary key
)
insert into #Tab select [Id] from [Info] ;
declare @ Id int
declare user_cur cursor for select [Id] from #Tab
open user_cur
fetch next from user_cur into @Id
while @@fetch_status=0
begin
print @ Id
select COUNT(*) from (select * from [Supply] where [UpdateTime] > @databegin and [UpdateTime] < @dataend and [Id] = @ Id) df
fetch next from user_cur into @ Id
end
close user_cur
deallocate user_cur
print @databegin
drop table #TabId
end