Bu ifade yanlıştır? Bir değişkene değer atayan bir SELECT ifadesi, veri alma işlemleriyle birleştirilmemelidir
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
Sadece, ben sadece ikinci select deyimi @adjustedLow kaldırıldı (hata neden oldu nerede aldıktan sonra) cevap açıklamak için.
Teşekkürler! cankurtaran! – Ramy
Sağlanan çözüm, sonuç kümesini almanıza ve değerlerden birini bir değişkene zorlamanıza izin vermez. Temel olarak, eğer bunu yapmanız gerekiyorsa (buradaki durumu değil, biliyorum), sorgunuzu iki kez yazmanız ve çalıştırmanız gerekir :( –