/*CREATE TABLE m_b (code VARCHAR(10),itemcount INT,type VARCHAR(30),amount MONEY)
insert into m_b values ('B001',1,'Dell',10)
insert into m_b values ('B001',1,'Dell',10)
insert into m_b values ('B001',1,'Apple',10)
insert into m_b values ('B001',2,'Apple',20)
insert into m_b values ('B001',2,'Apple',20)
insert into m_b values ('B114',1,'Apple',30.5)
insert into m_b values ('B114',1,'Apple',10) */
--SELECT * INTO #temp FROM m_c WHERE 1=2
DECLARE cur_test CURSOR
FOR SELECT Jobid,start,end_date,dayrate FROM m_c
go
DECLARE @Jobid INT
DECLARE @start DATE,@end_date DATE
DECLARE @dayrate INT
OPEN cur_test
FETCH cur_test INTO @Jobid,@start,@end_date,@dayrate
--BEGIN
DECLARE @jan INT
SET @jan=0
WHILE (@@sqlstatus != 2)
BEGIN
IF month(@start)=1
BEGIN
SELECT @jan= @jan + datediff(dd,'2013-01-31',@start)
-- testing purpose
INSERT INTO #temp VALUES (@jan,@start,@end_date,56)
END
IF month(@end_date)=1
BEGIN
SELECT @jan= @jan + datediff(dd,'2013-01-31',@end_date)
-- testing purpose
INSERT INTO #temp VALUES (@jan,@start,@end_date,57)
END
FETCH cur_test INTO @Jobid,@start,@end_date,@dayrate
END
SELECT @jan
WAITFOR delay '00:00:10'
CLOSE cur_test
DEALLOCATE CURSOR cur_test
--END
SELECT * FROM #temp
--TRUNCATE TABLE #temp
質問する
445 次