Отрабатывает...exec dbo.ac_cost @where_='' я пробелы вообще убрал.
Похоже на какой то глюк АДО. Процедура вот
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[ac_cost]
@where_ as varchar(255)
as
BEGIN
declare @sum_ float,
@sum1 float,
@sum2 float,
@rt varchar(500)
IF OBJECT_ID('tempdb..#_TT') IS NOT NULL
DROP TABLE #_TT
create table #_TT (sm float)
set @rt = ('insert into #_TT (sm) SELECT SUM(isnull(v.ac_mtrsum, 0) * CASE WHEN ((vl.id=1) or (vl.ShortDescr is null)) THEN 1
ELSE dbo.get_curs_for_date(vl.ShortDescr, getdate())
END) AS sm
FROM dbo.ul_AP_view v LEFT JOIN dbo.UL_Valute vl ON (v.ac_valute_ext = vl.id)
WHERE (v.HasExtension=0) and (v.del=0) and (v.ac_status<>3) ')
--WHERE (v.HasExtension=0) and (v.del=0) and (v.ac_status<>3) ' + @where_)
exec(@rt)
select @sum1 = coalesce((select sm from #_TT),0)
delete from #_TT
set @rt = ('insert into #_TT (sm) select SUM(isnull(v.ac_mtrsum_ext, 0) * CASE
WHEN (vl.id=1) or (vl.ShortDescr is null) THEN 1
ELSE dbo.get_curs_for_date(vl.ShortDescr, getdate())
END) AS sm
FROM dbo.ul_AP_view v LEFT JOIN dbo.UL_Valute vl ON (v.ac_valute_ext = vl.id)
WHERE (v.HasExtension=0) and (v.del=0) and (v.ac_status<>3) ')
exec(@rt)
select @sum2 = coalesce((select sm from #_TT),0)
select @sum_ = coalesce(@sum1,0) + coalesce(@sum2,0)
select @sum_ as sm
END