Testing my first Table Valued Function, I get no data, even while the SELECT works.
Not returning anything:
select * from GetMvtHistory('C1505 BLACK')
Returning correct data:
select row_number() OVER (order by DocId) as Id, detailId, Quant, 0 as Cumul
FROM vwDetailsHist
WHERE refer = 'C1505 BLACK'
ORDER BY DocId;
TVF code:
ALTER FUNCTION [dbo].[GetMvtHistory]
(@Ref char(10))
RETURNS @MvtHist table
(
Id int,
[DetailId] int NULL,
[Quant] int NULL,
[Cumul] int NULL
)
WITH EXEC AS CALLER
AS
BEGIN
INSERT into @MvtHist
select row_number() OVER (order by DocId) as Id, detailId, Quant, 0 as Cumul
FROM vwDetailsHist
WHERE refer = @Ref
ORDER BY DocId;
RETURN
What am I missing ?? Thanks !