Salut, la rularea urmatorului select primesc eroarea din Subject....aveti idee de ce?.....cum pot s-o evit (cu siguranta esle legata de conditia din where unde functie = functie (--and dbo.GetGrupareByIDTipMatricola(dbf.id_tipmatr,dbf.id_matr) =dbo.GetGrupareByIDTipMatricola(p.id_tipmatr,p.id_matr)) )......daca o scot intoarce ceva dar nu datele pe care mi le doresc
declare
@dataCurenta smalldatetime,
@idprim uniqueidentifier,
@filtru_tip_persoana tinyint,
set @dataCurenta = getdate()
set @idprim = 'B9F77393-F3EA-46C5-BA15-FB70C6199A20'
set @filtru_tip_persoana = 1
IF @filtru_tip_persoana = 1
begin
select dbo.GetGrupareByIDTipMatricola(dbf.id_tipmatr,dbf.id_matr) as grup,
dbf.an,
coalesce(
(select sum(suma)from gotax.dbo.debite_pf p
where
p.id_tipdebit = 2
and p.an = dbf.an
and dbo.GetGrupareByIDTipMatricola(dbf.id_tipmatr,dbf.id_matr)
=
dbo.GetGrupareByIDTipMatricola(p.id_tipmatr,p.id_matr)
),0) as ramasite,
coalesce(
(select sum(suma)from gotax.dbo.debite_pf p
where
(p.id_tipdebit = 5 or p.id_tipdebit = 8)
and p.an = dbf.an
and dbo.GetGrupareByIDTipMatricola(dbf.id_tipmatr,dbf.id_matr)
=
dbo.GetGrupareByIDTipMatricola(p.id_tipmatr,p.id_matr)
),0) as accesorii
from gotax.dbo.roluri_fiz r
inner join gotax.dbo.debite_pf dbf
on r.id = dbf.id_rol
where r.id_prim = @idprim and
dbf.id_tipdebit in (2,5,8)
and dbf.an <= year(@dataCurenta)
group by dbf.an,dbo.GetGrupareByIDTipMatricola(dbf.id_tipmatr,dbf.id_matr)
end
functia este:
CREATE FUNCTION GetGrupareByIDTipMatricola (@id_tipmatr tinyint,@id_matr uniqueidentifier)
RETURNS varchar(100) AS
BEGIN
declare @aux varchar(100)
if @id_tipmatr = 1 SET @Aux = (select label from gotax.dbo.tip_matricole where id = 1)
if @id_tipmatr = 2
begin
SET @Aux =(select label from gotax.dbo.tip_matricole where id = 2)
end
if @id_tipmatr = 3 SET @Aux = (select label from gotax.dbo.tip_matricole where id = 3)
if @id_tipmatr = 4 SET @Aux =
(select denumire from gotax.dbo.tip_alte_taxe where id =
coalesce(
(select id_tipalte from gotax.dbo.matricole_alte_pf where id = @id_matr),
(select id_tipalte from gotax.dbo.matricole_alte_pj where id = @id_matr)
)
)
return @aux
END
multumesc mult.
alex.