このクエリを確認してください:
declare @T table
(
FirstColumn datetime primary key,
S_E1 float
)
insert into @T(FirstColumn, S_E1) values
('2012-01-01T00:00:01', 1),
('2012-01-01T00:00:02', 2),
('2012-01-01T00:00:03', 3),
('2012-01-01T00:00:04', 4),
('2012-01-01T00:00:05', 5),
('2012-01-01T00:00:06', 6)
declare @Take varchar = '1'
declare @StartDate varchar(10)='2012-01-01T00:00:01'
declare @EndDate varchar(10) = '2012-01-01T00:00:06'
declare @count varchar(Max)
DECLARE @SQL nvarchar(Max)
set @count = (select count(FirstColumn) from @T Where FirstColumn Between ''+@StartDate+'' and ''+@EndDate+'')
set @SQL =' select S_E1 from @T where S_E1 ='+ @Take+''
BEGIN try
while(CAST(@Take AS int) < CAST(@count AS int))
Begin
print @SQL;
set @Take = CONVERT(varchar,CAST(@Take AS int)+1)
end
END TRY
BEGIN CATCH
select ERROR_MESSAGE() as errormessage
END CATCH
問題: 上記のクエリでは、@Take変数の値を更新できません。間違った方向に進んでいる場所を教えてください。