la función...
ALTER FUNCTION [dbo].[fnc_hab_merc_formularioImportacion] (@ref char(8),@fecha date)
RETURNS TABLE
AS
RETURN
(
select top 1
m.id,strreferencia,m.strbl,strformulario,mf.dtmfecha from tbl_hab_merc_manifiesto m
inner join tbl_hab_merc_manifiestocomplemento mf
on m.strbl=mf.strbl
select max(id) from (
select
m.id,strreferencia,m.strbl,strformulario,mf.dtmfecha from tbl_hab_merc_manifiesto m
inner join tbl_hab_merc_manifiestocomplemento mf
on m.strbl=mf.strbl where mf.dtmfecha<= @fecha) dt group by strreferencia) and strreferencia=@ref
order by dtmfecha desc
)
la consulta que hago
select a.*,fn.strformulario from detalle_postscript a left outer join fnc_hab_merc_formularioImportacion(a.referencia,@fecha) fn
on referencia=fn.strreferencia collate Modern_Spanish_CI_AS
where numero='01708002'
el error
Msg 4104, Level 16, State 1, Line 151
The multi-part identifier "a.referencia" could not be bound.
Quien me pueda decir que falta, que hay malo mil gracias