What is wrong with this statement?
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
Just to explain the answer (after getting where the error was caused), I simply removed @adjustedLow from the second select statement.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…