이 문이 잘못되었습니다. 변수에 값을 할당하는 SELECT 문을 데이터 검색 작업과 결합해서는 안됩니다
ALTER Function [InvestmentReturn].[getSecurityMinLowForPeriod](@securityid int,
@start datetime,
@end datetime)
returns xml
begin
declare @results varchar(500)
declare @low int
declare @adjustedLow int
declare @day varchar(10)
if @end is null
begin
set @end = getdate()
end
set @adjustedLow = (select min(adjLow)
from (
select Low * [InvestmentReturn].[fn_getCorporateActionSplitFactor](isq.securityid, @start, convert(varchar,day, 111)) as adjLow
from
securityquote isq
where isq.securityid = @securityid and isq.day >= convert(varchar(10), @start, 111) and convert(varchar(10), @end, 111) >= isq.day
and low != -1
) as x)
select
top 1 @low = low
, @day = day
, @adjustedLow
--select high
from
securityquote sq
where
day >= convert(varchar(10), @start, 111) and convert(varchar(10), @end, 111) >= day
and securityid = @securityid and low != -1
order by low asc
set @results= '<results type="debug_min">'
set @results = @results + '<periodStart>' + coalesce(cast(@start as varchar(20)), 'NULL') + '</periodStart>'
set @results = @results + '<periodEnd>' + coalesce(cast(@end as varchar(20)), 'NULL') + '</periodEnd>'
set @results = @results + '<securityID>' + coalesce(cast(@securityID as varchar(10)), 'NULL') + '</securityID>'
set @results = @results + '<periodMin>' + coalesce(cast(@low as varchar(10)), '-11111') + '</periodMin>'
set @results = @results + '<coraxAdjustedPeriodMin>' + coalesce(cast(@adjustedLow as varchar(10)), '-11111') + '</coraxAdjustedPeriodMin>'
set @results = @results + '<dayMinOcurred>' + coalesce(@day, 'NULL') + '</dayMinOcurred>'
set @results = @results + '</results>'
return @results
는 그냥 단순히 두 번째 select 문에서 @adjustedLow을 제거 (오류가 발생 된 곳 점점 후) 답을 설명합니다.
감사합니다. 생명의 은인! – Ramy
글쎄, 제공된 해결 방법은 결과 집합을 가져오고 값 중 하나를 변수로 푸시하지 못하게합니다. 그래서 기본적으로, 당신이 이것을 할 필요가 있다면 (내가 아는 경우는 아닙니다.) 그러면 쿼리를 두 번 쓰고 실행해야합니다 : ( –